tmake use of dc to autoincrement post number - monochromatic - monochromatic blog: http://blog.z3bra.org
(HTM) git clone git://z3bra.org/monochromatic
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) commit 3067822909d9daf2fe6e62707496bc530a280488
(DIR) parent d5d9e16dec289c57b8e7b615e625bb2addcbcc56
(HTM) Author: z3bra <willy@mailoo.org>
Date: Mon, 20 Apr 2015 00:59:45 +0200
make use of dc to autoincrement post number
Diffstat:
M publi.sh | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
---
(DIR) diff --git a/publi.sh b/publi.sh
t@@ -4,16 +4,20 @@ link=$(ls -l last.txt | sed 's^.*-> /')
test -z "$EDITOR" && EDITOR=vi
-sed '1s/^# /* 0x0000 - /;1p;d' last.txt > tmp.txt
-sed -i "s(#)(${link/.txt/.html})" tmp.txt
+# get last number used (in hexa) and increment it
+last=$(<index.txt cut -d' ' -f2 | sed 's/0x0*//;1q')
+next=$(printf "0x%04x" `echo "1 16i${last}+p"|dc`)
-$EDITOR tmp.txt
+# format our title and put it in a temp file
+sed '1s/^# /* '$next' - /;1p;d' last.txt > tmp.txt
+sed -i "s(#)(${link/.txt/.html})" tmp.txt
+# present out the final index for reviewing
cat index.txt >> tmp.txt
-
sed 10q tmp.txt
-echo -n 'Is everything okay? [N/y] '
+printf 'Is everything okay? [N/y] '
read choice
+# replace the index with the temp file
test "$choice" = "y" && mv tmp.txt index.txt