summaryrefslogtreecommitdiff
path: root/lists.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lists.sh')
-rwxr-xr-xlists.sh66
1 files changed, 0 insertions, 66 deletions
diff --git a/lists.sh b/lists.sh
deleted file mode 100755
index c07870a..0000000
--- a/lists.sh
+++ /dev/null
@@ -1,66 +0,0 @@
1#!/usr/bin/env bash
2
3shopt -s extglob nullglob
4
5. ./getopts_long.sh
6
7find_lists() {
8 LISTS=()
9 while read -r -d $'\0'; do
10 local list=$(realpath --relative-to=. "$REPLY")
11 LISTS+=("$list")
12 done < <(find lists -maxdepth 1 -mindepth 1 -type d -not -name '.*' -print0 | sort -z)
13}
14
15find_posts() {
16 local list="$1"
17 shift 1
18
19 POSTS=()
20 for p in "$list"/!(*[!0-9]*); do
21 POSTS+=( "$p" )
22 done
23}
24
25print_lists() {
26 find_lists
27 for x in "${LISTS[@]}"; do
28 printf "%s: %s\n" "$x" "$(<$x/title)"
29 done
30}
31
32print_posts() {
33 find_posts "$1"
34 for p in "${POSTS[@]}"; do
35 local post=$(readlink "$p")
36 printf "%s: %s\n" "${p##*/}" "${post##*/}"
37 done
38}
39
40add_list() {
41 local list="$1"
42 mkdir lists/"$list"
43 shift 1
44 echo "$@" >lists/"$list"/title
45}
46
47while getopts_long ":la:" opt \
48 posts required_argument \
49 "" "$@"
50do
51 case $opt in
52 l)
53 print_lists
54 exit 0;;
55 a)
56 shift "$(($OPTLIND - 1))"
57 add_list "$OPTLARG" "$@"
58 exit 0;;
59 posts)
60 print_posts "$OPTLARG"
61 ;;
62 :)
63 printf >&2 '%s: %s\n' "${0##*/}" "$OPTLERR"
64 exit 1;;
65 esac
66done