This commit is contained in:
2025-03-16 17:37:02 +01:00
parent 77e3c5b77c
commit 15e2f388b2
5 changed files with 72 additions and 12 deletions

View File

@@ -1,28 +1,38 @@
{
"shebang": {
// TODO: find a better prefix
// "__COMMENT__": "TODO: find a better prefix",
"prefix": "env",
"body": "#!/usr/bin/env bash$0",
"description": "Bash snippet 'env'"
},
"confirm": {
"prefix": "confirm",
"body": "gum confirm \"${1:Are you sure?}\" --default=yes$0",
"description": "Bash snippet 'confirm'"
},
"if": {
"prefix": "if",
"body": "if [[ $1 ]]; then\n $0\nfi",
"body": "if ${2:[[ $1 ]]}; then\n\t$0\nfi",
"description": "Bash snippet 'if'"
},
"while": {
"prefix": "while",
"body": "while read ${1:line}; do\n $0\ndone",
"body": "while read ${1:line}; do\n\t$2\ndone$0",
"description": "Bash snippet 'while'"
},
"for": {
"prefix": "for",
"body": "for ${1:i} in ${2:\"\\${array[@]\\}\"}; do\n $0\ndone",
"description": "Bash snippet 'for'"
"foreach": {
"prefix": "for-in",
"body": "for ${1:i} in ${3:\"\\${${2:array}[@]\\}\"}; do\n\t$4\ndone$0",
"description": "Bash snippet 'foreach'"
},
"for-range": {
"prefix": "for-range",
"body": "for ${1:i} in ${4:{${2:1}..${3:10}\\}}; do\n\t$5\ndone$0",
"description": "Bash snippet 'for-in'"
},
"case": {
"prefix": "case",
"body": "case ${1:EXPRESSION} in\n ${2:PATTERN})\n ${3:STATEMENTS}\n ;;\n *)\n ${4:STATEMENTS}\n ;;\nesac$0",
"body": "case ${1:EXPRESSION} in\n\t${2:PATTERN})\n\t\t${3:STATEMENTS}\n\t\t;;\n\t*)\n\t\t${4:STATEMENTS}\n\t\t;;\nesac$0",
"description": "Bash snippet 'case'"
},
"local": {
@@ -50,19 +60,39 @@
"body": "\"\\${#$1[@]\\}\"$0",
"description": "Bash snippet 'length'"
},
"join-array": {
"prefix": "join-array",
"body": "\"\\$(IFS=${1:\\$'\\n'}; printf \"%s\" \"\\${${2:arr}[*]}\")\"$0",
"description": "Bash snippet 'join-array'"
},
"variable": {
"prefix": "var",
"body": "\"\\${$1\\}\"$0",
"body": "${2:\"}\\${$1\\}${2:\"}$0",
"description": "Bash snippet 'variable'"
},
"subshell": {
"prefix": "sub",
"prefix": "subshell",
"body": "\"\\$($1)\"$0",
"description": "Bash snippet 'subshell'"
},
"subshell-multiline": {
"prefix": "subshell-multiline",
"body": "${1:tmpcmd}() {\n\t${2:BODY}\n}\n\"\\$(declare -f ${1:tmpcmd}); ${1:tmpcmd} \\\"\\$@\\\"\"\nunset -f ${1:tmpcmd}$0",
"description": "Bash snippet 'subshell-multiline'"
},
"math": {
"prefix": "math",
"body": "\\$(($1))$0",
"description": "Bash snippet 'math'"
},
"heredoc": {
"prefix": "eof",
"body": "<<-\"${1:EOF}\"\n\t${2:BODY}\n${1:EOF}\n$0",
"description": "Bash snippet 'heredoc'"
},
"has": {
"prefix": "has",
"body": "command -v ${1:cmd} >/dev/null$0",
"description": "Bash snippet 'has'"
}
}