blob: 9169f1a7d0624f3daa2edb33ab549aca3692f148 (
plain) (
blame)
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
|
#!/bin/sh
# poem: write a poem
begins_with() { # haystack prefix
value=$1
prefix=$2
case "$value" in
"$prefix"*) return 0
esac
return 1
}
usage() {
echo "poem [help | ls | ls-html | NAME]"
}
fuzzy() {
FILE="$(find "$WWW_DEFAULT_PATH/src/poetry" -type f | $FUZZY)"
[ -z "$FILE" ] && exit 0
if ! begins_with "$FILE" "$WWW_DEFAULT_PATH/src/poetry" ; then
FILE="$WWW_DEFAULT_PATH/src/poetry/$FILE"
fi
mkdir "$(dirname "$FILE")" -p
$EDITOR "$FILE"
}
list() {
header="Date\tTitle\n"
for f in $(find $WWW_DEFAULT_PATH/src/poetry -type f | sort -k 3) ; do
out="$out$(sed -n 2p $f)\t$(sed -n 1p $f)\n"
done
out="$header$(printf "$out" | sort -rk 1)\n"
printf "$out"
}
list_html() {
header="<table>\n<tr><th>Date</th>\t<th>Title</th></tr>\n"
for f in $(find $WWW_DEFAULT_PATH/src/poetry -type f | sort -k 3) ; do
out="$out\t<tr><td>$(sed -n 2p $f)</td><td><a href=\"/poetry/$(basename "$f")\">$(sed -n 1p $f)</a></td></tr>\n"
done
out="$header$(printf "$out" | sort -rk 1)\n</table>\n"
printf "$out"
}
[ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1
[ -z "$EDITOR" ] && echo "EDITOR not set" && exit
[ -z "$FUZZY" ] && echo "FUZZY not set" && exit
[ "$1" = "help" ] && usage && exit 0
[ "$1" = "ls" ] && list && exit 0
[ "$1" = "ls-html" ] && list_html && exit 0
if [ -z "$1" ] || [ "$1" = "fuzzy" ] ;
then
fuzzy
exit 0
fi
mkdir -p "$WWW_DEFAULT_PATH/src/poetry"
$EDITOR "$WWW_DEFAULT_PATH/src/poetry/$1"
|