#!/bin/sh # blog: write a blog entry begins_with() { # haystack prefix value=$1 prefix=$2 case "$value" in "$prefix"*) return 0 esac return 1 } usage() { echo "blog [help | ls | ls-html | NAME]" } fuzzy() { FILE="$(find "$WWW_DEFAULT_PATH/src/blog" -type f | $FUZZY -l 1000)" [ -z "$FILE" ] && exit 0 if ! begins_with "$FILE" "$WWW_DEFAULT_PATH/src/blog" ; then FILE="$WWW_DEFAULT_PATH/src/blog/$FILE" fi mkdir "$(dirname "$FILE")" -p $EDITOR "$FILE" } list() { header="Date\tTitle\n" for f in $(find $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do out="$out$(sed -n 2p $f) $(sed -n 1p $f)\n" done out="$header$(printf "$out" | sort -rk 1)\n" printf "$out" } list_html() { header="\n\t\n" for f in $(find $WWW_DEFAULT_PATH/src/blog -type f | sort -k 3) ; do out="$out\t\n" done out="$header$(printf "$out" | sort -rk 1)\n
DateTitle
$(sed -n 2p $f)$(sed -n 1p $f)
\n" printf "$out" } [ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 [ -z "$EDITOR" ] && echo "EDITOR not set" && exit [ -z "$FUZZY" ] && echo "FUZZY not set" && exit [ "$1" = "help" ] && usage && exit 0 [ "$1" = "ls" ] && list && exit 0 [ "$1" = "ls-html" ] && list_html && exit 0 if [ -z "$1" ] || [ "$1" = "fuzzy" ] ; then fuzzy exit 0 fi mkdir -p "$WWW_DEFAULT_PATH/src/blog" $EDITOR "$WWW_DEFAULT_PATH/src/blog/$1"