mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 14:12:41 +00:00
Updated newx script to show usage
This commit is contained in:
2
scripts/scripts/--help
Executable file
2
scripts/scripts/--help
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
2
scripts/scripts/-h
Executable file
2
scripts/scripts/-h
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
@@ -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"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user