#!/bin/sh # nbpost -- script for drafting journal entries using a # template file as a starting point, written # with nano-blogger in mind (bash blog engine) # Copyleft (C) 2008 Adrian C. # All rights reversed ext="txt" exw="htm" #doc="post" doc="html" nbe="${HOME}/blog/nb" tmp="${HOME}/blog/draft.tmpl" dir="${HOME}/blog/website/drafts" hlp="Usage: `basename $0` [-h] [-g] [-l] draftName\n\t -h\t-- display this help message\ \n\t -g\t-- create a draft or a preview\n\t -l\t-- list all unpublished drafts" umask 077 if [ "$#" -eq 0 ]; then echo -e "$hlp" exit 0 elif [ "$1" == "-l" ]; then basename -a -s ".${ext}" `ls -A -B -1 "${dir}"` exit 0 elif [ "$1" == "-h" ]; then echo -e "$hlp" exit 0 elif [ -z "$2" ]; then draft_name="$1" else draft_name="$2" fi if ! `echo ${draft_name} | grep -q "^[[:alnum:]]\+$"`; then echo "Name must contain alphanumeric characters only" exit 1 fi if [ ! -r "/tmp/emacs${UID}/server" ]; then emacs --daemon fi draft_file="${dir}/${draft_name}.${ext}" if [ -f "${draft_file}" ]; then if [ "$1" == "-g" ]; then draft_prev="${dir}/${draft_name}.${exw}" ${nbe} make-page "${draft_file}" "${draft_prev}" firefox "${draft_prev}" rm -f "${draft_prev}" else emacsclient --eval "(find-file \"${draft_file}\")" "(${doc}-mode)" fi else touch "${draft_file}" # so we can enforce the umask emacsclient --eval "(find-file \"${draft_file}\")" "(insert-file \"${tmp}\")" "(${doc}-mode)" fi