addscript (471B)
1 #!/bin/sh 2 3 # Configuration 4 [ -n "$BIN_HOME" ] \ 5 && dir="$BIN_HOME" \ 6 || dir="$HOME/.local/bin" 7 8 usage() { 9 echo "addscript -- create boilerplate executable file and edit" 10 echo 11 echo "Usage: addscript NAME" 12 exit 1 13 } 14 15 [ -z "$1" ] || [ "$1" = "-h" ] && usage 16 17 filename="$dir/$1" 18 19 # File already exists 20 [ -f "$filename" ] && $EDITOR "$filename" && exit 21 22 # File does not exist 23 echo "#!/bin/sh\n\n" > "$filename" 24 chmod +x "$filename" 25 $EDITOR "$filename" 26