commit 5eaf58b644c2c5d3e79f1e4b7c6a6551de341b41 parent c42620ff087363e77f8c53e3de4f967cac9cc3df Author: Alex Balgavy <a.balgavy@gmail.com> Date: Thu, 15 Aug 2019 19:43:37 +0200 vim: more snippets Former-commit-id: 7d0cc3eadd87eb17d4b3218363fd6689b3131e45 Diffstat:
M | vim/ultisnips/sh.snippets | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 45 insertions(+), 0 deletions(-)
diff --git a/vim/ultisnips/sh.snippets b/vim/ultisnips/sh.snippets @@ -19,3 +19,48 @@ case "$${1:variable}" in ;; esac endsnippet + +snippet argparse "Parse arguments/flags" b +PARAMS="" + +while (( "\$#" )); do + case "\$1" in + -${1:letter}|--${2:long name}) + $2="\$2" + shift 2 + ;; + $0 + -h|--help) + echo "Usage:" + echo "${3:usage text}" + exit 0 + ;; + --) # end arg parsing + shift + break + ;; + -*) # unsupported flags + echo "Unsupported flag \$1" >&2 + exit 1 + ;; + *) # preserve positional arguments + PARAMS="\$PARAMS \$1" + shift + ;; + esac +done +eval set -- "\$PARAMS" +endsnippet + +snippet bash "Bash shebang" b +#!/usr/bin/env bash +$0 +endsnippet + +snippet exists "Check if command exists" w,A +if ! command -v ${1:command} &>/dev/null; then + echo "$1 not installed." >&2 + exit 1 +fi +$0 +endsnippet