From: Colin Watson Date: Mon, 2 Dec 2002 05:27:02 +0000 (+0000) Subject: get-sig: Improve shell use a bit. Take base directories relative to $HOME. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?p=bin.git;a=commitdiff_plain;h=11b0e8cceae29f8cce2920e90ac9299119bf8e18 get-sig: Improve shell use a bit. Take base directories relative to $HOME. Print an error message and exit if the given signature group doesn't exist. --- diff --git a/get-sig b/get-sig index f15776b..24da9bb 100755 --- a/get-sig +++ b/get-sig @@ -2,19 +2,24 @@ if [ "X$1" == "X" ]; then NAME=$(grep '^\*' ~/.siglist | head -1 | tr -s '\t' ' ' | cut -d' ' -f2) - if [ "X$NAME" == "X" ]; then - echo "Usage: $0 signature-name [pattern]" 2>&1 + if [ -z "$NAME" ]; then + echo "Usage: $0 signature-group [pattern]" >&2 exit 1 fi else NAME=$1 fi -ARGS=$(grep ^$NAME'\>' ~/.siglist | head -1 | tr -s '\t' ' ' | cut -d' ' -f2-) -BASEDIR=$(eval echo $(echo $ARGS | cut -d' ' -f1)) -STATICFILE=$(eval echo $(echo $ARGS | cut -d' ' -f2)) -FORTUNEARGS=$(eval echo $(echo $ARGS | cut -d' ' -f3-)) +ARGS=$(grep "^$NAME\\>" ~/.siglist | head -1 | tr -s '\t' ' ' | cut -d' ' -f2-) +if [ -z "$ARGS" ]; then + echo "No such signature group: $NAME" >&2 + exit 1 +fi + +BASEDIR=$(eval echo $(echo "$ARGS" | cut -d' ' -f1)) +STATICFILE=$(eval echo $(echo "$ARGS" | cut -d' ' -f2)) +FORTUNEARGS=$(eval echo $(echo "$ARGS" | cut -d' ' -f3-)) -cd $BASEDIR -cat $STATICFILE -if [ "$2" ]; then fortune $FORTUNEARGS -m $2; else fortune $FORTUNEARGS; fi +cd "$HOME/$BASEDIR" +cat "$STATICFILE" +if [ "$2" ]; then fortune $FORTUNEARGS -m "$2"; else fortune $FORTUNEARGS; fi