mk-sh-script
A function to place in ~/.bashrc
or a zsh aliases file to prime new shell scripts:
function mk-sh-script {
readonly local filename=$(basename $1)
local dirname=$(dirname $1)
if [[ -z $dirname || ($dirname == "." && ${1:0:1} != ".") ]]; then
dirname=$HOME/bin
fi
if [[ ! -d $dirname ]]; then
echo "Directory $dirname does not exist"
return
fi
readonly local target="$dirname/$filename"
if [[ ! -f $target ]]; then
echo "#!/usr/bin/env bash
set -o nounset
set -o errexit
" > $target
chmod +x $target
fi
$EDITOR +6 $HOME/bin/$@
}
Written by Charles Feduke
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#