]> git.rmz.io Git - dotfiles.git/blobdiff - vim/ultisnips/sh.snippets
vim: add choice snippet for sh
[dotfiles.git] / vim / ultisnips / sh.snippets
index f17a0b58cd8f4710b02b40d9ab3f9cac12e2ac76..45d5f810452b431759931debb6e552d53ef91039 100644 (file)
@@ -12,6 +12,16 @@ snippet ar "${array[@]}" w
 \${${1:array}[${2:@}]}$0
 endsnippet
 
+snippet choice "Read a choice from stdin" b
+read -r -p "${1:Question?} [Yn] " choice
+case "$choice" in
+       Y|y) echo "yes" ;;
+       '')  echo "yes" ;;
+       N|n) echo "no"  ;;
+       *)   echo "invalid"
+esac
+endsnippet
+
 snippet readline "Read a file line by line" b
 while ${1:IFS='' }read -r ${2:line} || [[ -n "$$2" ]]; do
        ${0:echo "Text read from file: $$2"}