From: Mark Szymanski Date: Mon, 20 Dec 2010 16:02:54 +0000 (-0600) Subject: Added 'editpost' function for jekyll plugins X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=3c0ea6784e26abc27d21781b0fdd3518e2576598;p=common%2Fbash_it.git Added 'editpost' function for jekyll plugins --- diff --git a/plugins/jekyll.plugins.bash b/plugins/jekyll.plugins.bash index 3ad9d0d..546bb63 100644 --- a/plugins/jekyll.plugins.bash +++ b/plugins/jekyll.plugins.bash @@ -1,5 +1,31 @@ #!/bin/bash +editpost() { + builtin cd "$JEKYLL_LOCAL_ROOT/_posts" + + COUNTER=1 + NUMBER="$RANDOM" + + for POST in * + do + DATE=`echo $POST | grep -oE "[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}"` + TITLE=`cat $POST | grep -oE "title: (.+)"` + TITLE=`echo $TITLE | sed 's/title: //'` + TMPFILE="/tmp/editpost-$NUMBER" + echo "$COUNTER) $DATE | $TITLE" >> "$TMPFILE" + POSTS[$COUNTER]=$POST + COUNTER=`expr $COUNTER + 1` + done + less $TMPFILE + read -p "Number of post to edit: " POST_TO_EDIT + if [ -z "$EDITOR" ] + then + nano "${POSTS[$POST_TO_EDIT]}" + else + "$EDITOR" "${POSTS[$POST_TO_EDIT]}" + fi +} + newpost() { # 'builtin cd' into the local jekyll root