From 367cae97484343aee64ef1a5df3b7f3126067b15 Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Tue, 7 Nov 2023 08:47:12 -0500 Subject: [PATCH] Updated newx script to show usage --- scripts/scripts/--help | 2 ++ scripts/scripts/-h | 2 ++ scripts/scripts/newx | 26 +++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 scripts/scripts/--help create mode 100755 scripts/scripts/-h diff --git a/scripts/scripts/--help b/scripts/scripts/--help new file mode 100755 index 0000000..6ef54a9 --- /dev/null +++ b/scripts/scripts/--help @@ -0,0 +1,2 @@ +#!/bin/zsh + diff --git a/scripts/scripts/-h b/scripts/scripts/-h new file mode 100755 index 0000000..6ef54a9 --- /dev/null +++ b/scripts/scripts/-h @@ -0,0 +1,2 @@ +#!/bin/zsh + diff --git a/scripts/scripts/newx b/scripts/scripts/newx index 682970d..aefb1d2 100755 --- a/scripts/scripts/newx +++ b/scripts/scripts/newx @@ -5,17 +5,37 @@ declare -a localOpt declare -a functionOpt declare -a shellOpt=("zsh") +declare -a helpOpt DEBUG="$(env | grep DEBUG)" zparseopts -D -K -- \ {l,-local}+:=localOpt \ {f,-function}+:=functionOpt \ - {s,-shell}+=shellOpt + {s,-shell}+=shellOpt \ + {h,-help}=helpOpt shell=${shellOpt[-1]} localPath=${localOpt[-1]} #-------------------- Helpers -------------------- +function usage() { + cat << EOF +newx: Create new executable (script, function, or local script). + +Typical usage: + + newx foo (creates new script named 'foo') + +Usage: newx [-l ] [-f ] [-s ] + + -l | --local : Create a script in current directory. + -f | --function : Create a function. + + Advanced options: + -s | --shell : Customize the shell for the script. +EOF + +} function debug_print() { [ -n "$DEBUG" ] \ @@ -46,6 +66,10 @@ function parse_local_path() { debug_print "first-arg: $1" +if [ -n "${helpOpt}" ]; then + usage && exit 0 +fi + if [ -n "${functionOpt[-1]}" ]; then debug_print "function-opt: $functionOpt"