snippet #! "#!/usr/bin/env (!env)" b #!/usr/bin/env bash endsnippet snippet !env "#!/usr/bin/env (!env)" b #!/usr/bin/env bash endsnippet snippet script_dir "Get dir of current script" b ${1:script_dir}="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" $0 endsnippet 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"} done < "\$${3:file}" endsnippet snippet getopt version="${1:0.1}" function usage () { echo "Usage : $${0:0} [options] Options: -h,--help Display this message -v,--version Display script version" } # Parse arguments declare -a args while [[ $# -gt 0 ]]; do opt="\$1" case $opt in -h|--help) usage; exit 0 ;; -v|--version) echo "$${0:0} -- Version $version"; exit 0 ;; -* ) echo -e "\n Option does not exist : $opt\n" usage; exit 1 ;; *) args+=("$opt"); shift ;; esac done endsnippet