commit 1bf5d209f4c5b549bef87d2d0c74fd468b6e8a6b parent fde5b4ed41c8b0ae4eba6bc8f3fcd857c3bdef99 Author: Alex Balgavy <a.balgavy@gmail.com> Date: Fri, 2 Oct 2020 15:00:45 +0200 vim: make shell snippets more portable Former-commit-id: bd6954cd390c91d9a2eacf17f4ce1eb1b8df1b9b Diffstat:
M | vim/ultisnips/sh.snippets | | | 23 | ++++++++++++++++++++++- |
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/vim/ultisnips/sh.snippets b/vim/ultisnips/sh.snippets @@ -23,7 +23,7 @@ endsnippet snippet argparse "Parse arguments/flags" b PARAMS="" -while (( "\$#" )); do +while [ \$(("\$#")) -ne 0 ]; do case "\$1" in -${1:letter}|--${2:long name}) $2="\$2" @@ -93,3 +93,24 @@ case "$conf" in esac $0 endsnippet + +snippet osdetect "Detect OS" b +os=\$(uname -s | tr '[:upper:]' '[:lower:]') +case "\$os" in + linux*) + ${1:# code for Linux} + ;; + darwin*) + ${2:# code for macOS} + ;; + msys*|cygwin*|mingw*|nt|win*) + ${3:# code for Windows} + ;; + *) + printf "Operating system %s is unknown.\n" "\$os" + ;; +esac +endsnippet +snippet contains "String contains substring" w +[ -z "\${${1:strvar}##*${2:substr}*}" ]$0 +endsnippet