Last active
October 3, 2018 19:06
-
-
Save brianloveswords/16aa5af66d3ffe73242ef8dc6728a58f to your computer and use it in GitHub Desktop.
mkbin: a shell script that makes shell scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# mkbin: create a new shell script and open the editor | |
mode="create" | |
if [ "$1" = "-e" ] || [ "$1" = "--edit" ]; then | |
mode="edit" | |
shift | |
fi | |
bin="$1" | |
fullpath="$HOME/bin/$1" | |
if [ -z "$bin" ]; then | |
echo "must pass bin name" | |
exit 1 | |
fi | |
if [ "$mode" = "edit" ]; then | |
if [ ! -f "$fullpath" ]; then | |
echo "$fullpath does not exist" | |
exit 1 | |
fi | |
"$EDITOR" "$fullpath" & | |
exit 1 | |
fi | |
if [ -f "$fullpath" ]; then | |
echo "file exists" | |
exit 1 | |
fi | |
cat >"$fullpath" <<EOF | |
#!/bin/bash | |
set -o errexit; set -o nounset; | |
# $1 - do stuff | |
EOF | |
chmod +x "$fullpath" | |
"$EDITOR" "$fullpath" & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment