From 631729fe093c72c521d7ba47e5fd3cfcef2b773b Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 21 Nov 2023 11:57:53 +0000 Subject: [PATCH] Add script to add new scripts --- nx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 nx diff --git a/nx b/nx new file mode 100755 index 0000000..003a76a --- /dev/null +++ b/nx @@ -0,0 +1,23 @@ +#!/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" + +test -n "$EDITOR" && $EDITOR "$fullpath" +test -n "$VISUAL" && $VISUAL "$fullpath" +if command -v vi 1>/dev/null; then + vi "$fullpath" +else + error "No editor program found (set \$EDITOR or \$VISUAL, or install \`vi\`)" +fi