summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2015-03-29 05:13:37 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2015-03-29 05:13:37 +0200
commit8c06691381964cf370e213b4dd8b588ca018590e (patch)
tree93cd90be2e3c3b0cc899711e4900a993194bf24b
parent39d63c72c63a3e1ac35ba5b05e4cbf054970ec20 (diff)
downloaddirty-haskell.org-8c06691381964cf370e213b4dd8b588ca018590e.tar
dirty-haskell.org-8c06691381964cf370e213b4dd8b588ca018590e.tar.gz
dirty-haskell.org-8c06691381964cf370e213b4dd8b588ca018590e.tar.bz2
dirty-haskell.org-8c06691381964cf370e213b4dd8b588ca018590e.tar.xz
dirty-haskell.org-8c06691381964cf370e213b4dd8b588ca018590e.zip
posts.sh now manages linking posts into lists
-rwxr-xr-xposts.sh17
1 files changed, 13 insertions, 4 deletions
diff --git a/posts.sh b/posts.sh
index a259dd4..464def8 100755
--- a/posts.sh
+++ b/posts.sh
@@ -2,6 +2,13 @@
2 2
3shopt -s extglob nullglob 3shopt -s extglob nullglob
4 4
5add_to_list() {
6 list=$(basename "$1")
7 file=$(basename "$2")
8 last_link=$(find ./lists/"$list" -regex '.*/[0-9]*$' -printf '%f\n' | sort | tail -n1)
9 new_link=$(printf '%03d\n' $(($last_link + 1)))
10 ln -s ../../posts/"$file" ./lists/"$list"/"$new_link"
11}
5 12
6new_post() { 13new_post() {
7 filename="$1" 14 filename="$1"
@@ -9,15 +16,13 @@ new_post() {
9 cat >posts/$filename <<EOF 16 cat >posts/$filename <<EOF
10% $@ 17% $@
11EOF 18EOF
12 last_link=$(find ./lists/zz_all -regex '.*/[0-9]*$' -printf '%f\n' | sort | tail -n1) 19 add_to_list zz_all "$filename"
13 new_link=$(printf '%03d\n' $(($last_link + 1)))
14 ln -s ../../posts/"$filename" ./lists/zz_all/"$new_link"
15} 20}
16 21
17 22
18. ./getopts_long.sh 23. ./getopts_long.sh
19 24
20while getopts_long ":n:" opt \ 25while getopts_long ":n:a:" opt \
21 "" "$@" 26 "" "$@"
22do 27do
23 case $opt in 28 case $opt in
@@ -25,6 +30,10 @@ do
25 shift "$(($OPTLIND - 1))" 30 shift "$(($OPTLIND - 1))"
26 new_post "$OPTLARG" "$@" 31 new_post "$OPTLARG" "$@"
27 exit 0;; 32 exit 0;;
33 a)
34 shift "$(($OPTLIND - 1))"
35 for f in $@; do add_to_list "$OPTLARG" $f; done
36 exit 0;;
28 :) 37 :)
29 printf >&2 '%s: %s\n' "${0##*/}" "$OPTLERR" 38 printf >&2 '%s: %s\n' "${0##*/}" "$OPTLERR"
30 exit 1;; 39 exit 1;;