summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToM <tom@leloop.org>2013-04-19 02:39:56 +0200
committerToM <tom@leloop.org>2013-04-19 02:47:13 +0200
commitf4b186be95750edba8585ccdee856328085d5121 (patch)
tree645d9c3ff2f0cc3b07189ce4b6136471495b0854
parent5a218d9ae118cda6824588e83704b9bbf6b4b1aa (diff)
[ENH] _newpost.sh script.
-rwxr-xr-x_newpost.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/_newpost.sh b/_newpost.sh
new file mode 100755
index 0000000..8bee238
--- /dev/null
+++ b/_newpost.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+#
+# Idea from https://github.com/likang/blogofile/blob/master/_new.sh
+#
+# TODO
+# --help
+# --format={markdown,...}
+
+show_usage()
+{
+ echo "Utilisation : $(basename $0) TITRE
+Cree un nouveau post a editer, au format markdown.
+
+TITRE devrait etre protege par des quotes, et eventuellement echappe
+autant que necessaire."
+ exit 0
+}
+
+if [ ! -d _controllers ]; then
+ echo "T'es perdu la coco. Lance-moi depuis la racine du depot Git !" >&2
+ exit 1
+fi
+
+if [ $# -eq 0 ]; then
+ echo "Error: no args." >&2
+ show_usage
+ exit 1
+fi
+
+
+
+#
+# magic happens here.
+#
+
+postdate=$(date '+%G-%m-%d')
+posttitle=$(echo "$1" | tr -s '[:blank:][:punct:]' '-') # filenames that suck less.
+postfile="_posts/${postdate}-${posttitle}.markdown"
+
+echo "\
+---
+categories:
+date: $(date '+%G/%m/%d %H:%M:%S')
+title: $1
+author: $(whoami)
+summary: \"I was too lame to edit the summary.\"
+---" >> "$postfile"
+
+if [ ! -x "$EDITOR" ]; then
+ echo "Votre (debut de) post : $postfile"
+else
+ $EDITOR "$postfile"
+fi