X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=_templates%2Fadd.sh;h=4aae1bf0c6e85541a4105c3d5cecf5f18dbf98e1;hb=27eebbcab5c33f46a4a103a43b1546c3472e5545;hp=35d9df0c76b7ba41e9a17bd18b14f915e1d953f3;hpb=9ae958ea61331c4bd061e4aab220ddeba616a1b0;p=senf.git diff --git a/_templates/add.sh b/_templates/add.sh index 35d9df0..4aae1bf 100755 --- a/_templates/add.sh +++ b/_templates/add.sh @@ -2,7 +2,7 @@ if [ -z "$1" ]; then cat <. [] +Usage: $0 [-f] . [] Will add the file with that name to the current directory by copying the appropriate template and replacing the @NAME@ placeholders @@ -23,14 +23,25 @@ If is given, it is also set correctly replaced. If is unset but the environment variable SENF_AUTHOR is set, it's value is used. Otherwise, the @AUTHOR@ placeholder will need to be replaced manually. + +$0 will refrain from overwriting existing files except when the '-f' +option is specified. EOF exit 1 fi base="`dirname "$0"`"; base="`cd "$base"; pwd`" -type="${1##*.}" -name="`basename "$1" ".$type"`" +if [ "$1" == "-f" ]; then + force=1 + shift +fi + +name="`basename "$1"`" +case "$name" in + *.*) type="${name#*.}"; name="${name%.$type}" ;; + *) type="" ;; +esac if [ ! -r "$base/Example.$type" ] ; then echo "Don't know about file type '$type'" @@ -39,7 +50,7 @@ fi [ -z "$2" ] || SENF_AUTHOR="$2" -if [ -r "$1" ] ; then +if [ -z "$force" -a -r "$1" ] ; then echo "Target file '$1' exists." exit 1 fi