Updated newx script to show usage

This commit is contained in:
2023-11-07 08:47:12 -05:00
parent 8e46610a7b
commit 367cae9748
3 changed files with 29 additions and 1 deletions

2
scripts/scripts/--help Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/zsh

2
scripts/scripts/-h Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/zsh

View File

@@ -5,17 +5,37 @@
declare -a localOpt declare -a localOpt
declare -a functionOpt declare -a functionOpt
declare -a shellOpt=("zsh") declare -a shellOpt=("zsh")
declare -a helpOpt
DEBUG="$(env | grep DEBUG)" DEBUG="$(env | grep DEBUG)"
zparseopts -D -K -- \ zparseopts -D -K -- \
{l,-local}+:=localOpt \ {l,-local}+:=localOpt \
{f,-function}+:=functionOpt \ {f,-function}+:=functionOpt \
{s,-shell}+=shellOpt {s,-shell}+=shellOpt \
{h,-help}=helpOpt
shell=${shellOpt[-1]} shell=${shellOpt[-1]}
localPath=${localOpt[-1]} localPath=${localOpt[-1]}
#-------------------- Helpers -------------------- #-------------------- 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 <name>] [-f <name>] [-s <shell>]
-l | --local <name>: Create a script in current directory.
-f | --function <name>: Create a function.
Advanced options:
-s | --shell <shell>: Customize the shell for the script.
EOF
}
function debug_print() { function debug_print() {
[ -n "$DEBUG" ] \ [ -n "$DEBUG" ] \
@@ -46,6 +66,10 @@ function parse_local_path() {
debug_print "first-arg: $1" debug_print "first-arg: $1"
if [ -n "${helpOpt}" ]; then
usage && exit 0
fi
if [ -n "${functionOpt[-1]}" ]; then if [ -n "${functionOpt[-1]}" ]; then
debug_print "function-opt: $functionOpt" debug_print "function-opt: $functionOpt"