Dernière activité 9 hours ago

Révision 81fb29c38169e8d45447dee5a8eb74d646b11bb5

andpile Brut Playground
1#!/usr/bin/env bash
2# A sketch, I would probably use this for nothing, lol
3if [[ ! -d "$HOME/.andpile" ]]; then
4 mkdir "$HOME/.andpile" ;
5 mkdir "$HOME/.andpile/data" ;
6 touch "$HOME/.andpile/feeds.txt" ;
7fi
8
9remove_feed() {
10 sed -i.back "$(($1 + 1))d" "$HOME/.andpile/feeds.txt" ;
11}
12
13add_feed () {
14 if grep -q "^$1" "$HOME/.andpile/feeds.txt" ; then
15 echo "Already subscribed to feed" ;
16 else
17 id="$(uuidgen)" ;
18 echo "Subscribing to feed..." ;
19 echo "$1 $id" >> "$HOME/.andpile/feeds.txt" ;
20 echo "Downloading listing..."
21 curl "$1" >> "$HOME/.andpile/data/$id.txt" ;
22 fi
23}
24
25
26feeds () {
27 readarray -t lines < "$HOME/.andpile/feeds.txt" ;
28 for index in "${!lines[@]}" ; do
29 line=${lines[$index]}
30 read url id <<< $line ;
31 read title < "$HOME/.andpile/data/$id.txt" ;
32 printf "%s: %s\n" "$index" "$title" ;
33 done
34}
35
36list_feed () {
37 readarray -t lines < "$HOME/.andpile/feeds.txt" ;
38 read url id <<< ${lines[$1]} ;
39 if [[ -f "$HOME/.andpile/data/$id.txt" ]]; then
40 curl "$url" > "$HOME/.andpile/data/$id.txt" ;
41 cat "$HOME/.andpile/data/$id.txt" | more ;
42 fi
43}
44
45case "$1" in
46 add-feed) add_feed "$2" ;;
47 remove-feed) remove_feed "$2" ;;
48 feeds) feeds ;;
49 list) list_feed "$2" ;;
50esac
51