From a4949584026429024a02c74d178701851818e7be Mon Sep 17 00:00:00 2001 From: hophacker Date: Sat, 20 Feb 2021 23:49:55 +0800 Subject: [PATCH] add zsh snippet getopt --- SpaceVim.d/snippets/zsh.snip | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 SpaceVim.d/snippets/zsh.snip diff --git a/SpaceVim.d/snippets/zsh.snip b/SpaceVim.d/snippets/zsh.snip new file mode 100644 index 0000000..5925b6b --- /dev/null +++ b/SpaceVim.d/snippets/zsh.snip @@ -0,0 +1,36 @@ +# getopt +snippet getopt + CMD=$${0:0} + function usage () + { + echo "Usage : $CMD [options] [--] + Options: + --debug Debug mode + --log-level=* Set Log Level + -h Display this message" + } + LOG_LEVEL=0 + DEBUG=false + while getopts ":h-:" opt + do + case "${opt}" in + -) + case "${OPTARG}" in + debug) + DEBUG=true + ;; + loglevel=*) + val=${OPTARG#*=} + opt=${OPTARG%=$val} + echo "${opt} is set to: ${val}" + ;; + *) + echo "Unknown option --${OPTARG}" + ;; + esac;; + h) usage; exit 0 ;; + *) echo -e "\n option does not exist : $optarg\n" + usage; exit 1 ;; + esac + done + shift $(($OPTIND-1))