aboutsummaryrefslogtreecommitdiff
path: root/sfeed-browser
blob: 774c8088ad19dfaf71d24441b3ba8a8fe6cc6f29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/sh

# This script is based on sfeed (https://codemadness.org/sfeed.html), but
# it allows you organize your feeds in directories and subdirectories.
# In your $sfd directory (see below) you should have two folders:
#	urls: it can contain more subfolders and files. Each file should contain
#		only one line with the url to the feed. The name of the file is the
#		name of the feed (it can contains spaces and such).
#	files: this one can be empty, it will be filled with the feed files
# An older version of this script also marked viewed items and removed
# them before displaying the choice of feeds. Contact me if you are interested
# in using it.

# Requires: sfeed, dmenu-file-picker (or similar), open-url (or similar)

# Usage: sfeed-browser [-m menu]

filepicker="dmenu-filepicker" # Try "nnn -p -"
menu="dmenu -l 35 -i"
urlopener=open-url
sfd="$HOME/box/sfeed"
showlast=10

usage() {
	echo "sfeed-browser [-m MENU]"
}

while getopts "m:" opt; do
	case "$opt" in
		m)
			menu="$OPTARG"
			;;
		*)
			usage
			exit 1
			;;
	esac
done

# Might add more stuff later
fixurl() {
	sed 's/old\.reddit\.com/reddit\.com/'
}

dirtofeedpaths() {
	while read -r line; do
		find "$line" | while read -r fname; do
			[ -f "$fname" ] && echo "$fname"
		done
	done
}

pathstosfeedrc() {
	printf 'sfeedpath="%s"\n\nfeeds() {\n' "$sfd/files"
	while read -r line; do
		feedname=$(echo "$line" | sed 's/.*\///')
		read -r feedurl <"$line"
		printf '\tfeed "%s" "%s"\n' "$feedname" "$feedurl"
	done
	printf "}\n"
}

feedmenu() {
	while read -r line; do
		feedname=$(echo "$line" | sed 's/.*\///')
		sfeed_plain "$sfd/files/$feedname" | head -$showlast
	done | $menu
}

openfeeds() {
	while read -r line; do
		url=$(echo "$line" | sed 's/.*[\t ]//' | fixurl)
		[ -n "$url" ] && echo "$url"
	done | xargs $urlopener
}

$filepicker "$@" "$sfd/urls" | dirtofeedpaths > "$sfd/last"
pathstosfeedrc < "$sfd/last" > "$sfd/sfeedrc"
sfeed_update "$sfd/sfeedrc"
feedmenu < "$sfd/last" | openfeeds

Generated with cgit - Back to sebastiano.tronto.net