summaryrefslogtreecommitdiff
path: root/posts.sh
diff options
context:
space:
mode:
Diffstat (limited to 'posts.sh')
-rwxr-xr-xposts.sh32
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
3shopt -s extglob nullglob
4
5
6new_post() {
7 filename="$1"
8 shift 1
9 cat >posts/$filename <<EOF
10% $@
11EOF
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
20while getopts_long ":n:" opt \
21 "" "$@"
22do
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
32done