scripts/nx

24 lines
558 B
Plaintext
Raw Permalink Normal View History

2023-11-21 11:57:53 +00:00
#!/bin/sh
set -e
error() {
echo "$@" 1>&2
exit 1
}
test ! -d "$HOME/code/scripts" && error "No $HOME/code/scripts/ directory found"
test -z "$1" && error "No script name given"
test -f "$1" && error "$1 already exists"
fullpath="$HOME/code/scripts/$1"
touch "$fullpath" && chmod +x "$fullpath"
2023-11-22 12:38:37 +00:00
test -n "$EDITOR" && $EDITOR "$fullpath" && exit 0
test -n "$VISUAL" && $VISUAL "$fullpath" && exit 0
2023-11-21 11:57:53 +00:00
if command -v vi 1>/dev/null; then
2023-11-22 12:38:37 +00:00
vi "$fullpath" && exit 0
2023-11-21 11:57:53 +00:00
else
error "No editor program found (set \$EDITOR or \$VISUAL, or install \`vi\`)"
fi