diff options
Diffstat (limited to 'posts.sh')
-rwxr-xr-x | posts.sh | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/posts.sh b/posts.sh new file mode 100755 index 0000000..a259dd4 --- /dev/null +++ b/posts.sh | |||
@@ -0,0 +1,32 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | shopt -s extglob nullglob | ||
4 | |||
5 | |||
6 | new_post() { | ||
7 | filename="$1" | ||
8 | shift 1 | ||
9 | cat >posts/$filename <<EOF | ||
10 | % $@ | ||
11 | EOF | ||
12 | last_link=$(find ./lists/zz_all -regex '.*/[0-9]*$' -printf '%f\n' | sort | tail -n1) | ||
13 | new_link=$(printf '%03d\n' $(($last_link + 1))) | ||
14 | ln -s ../../posts/"$filename" ./lists/zz_all/"$new_link" | ||
15 | } | ||
16 | |||
17 | |||
18 | . ./getopts_long.sh | ||
19 | |||
20 | while getopts_long ":n:" opt \ | ||
21 | "" "$@" | ||
22 | do | ||
23 | case $opt in | ||
24 | n) | ||
25 | shift "$(($OPTLIND - 1))" | ||
26 | new_post "$OPTLARG" "$@" | ||
27 | exit 0;; | ||
28 | :) | ||
29 | printf >&2 '%s: %s\n' "${0##*/}" "$OPTLERR" | ||
30 | exit 1;; | ||
31 | esac | ||
32 | done | ||