From ca67c97c271ff3c26ab29f10312e8cea653f5d4d Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 16 Mar 2025 23:16:42 +0100 Subject: [PATCH] lkjdasljdsaldsalkj --- snippets/shell script.json | 47 +++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/snippets/shell script.json b/snippets/shell script.json index 4404a00..0a250ab 100644 --- a/snippets/shell script.json +++ b/snippets/shell script.json @@ -1,10 +1,15 @@ { - "shebang": { - // "__COMMENT__": "TODO: find a better prefix", + "env": { + // TODO: find a better prefix "prefix": "env", "body": "#!/usr/bin/env bash$0", "description": "Bash snippet 'env'" }, + "todo": { + "prefix": "todo", + "body": "# TODO: $0", + "description": "Bash snippet 'todo'" + }, "confirm": { "prefix": "confirm", "body": "gum confirm \"${1:Are you sure?}\" --default=yes$0", @@ -21,10 +26,20 @@ "description": "Bash snippet 'while'" }, "foreach": { - "prefix": "for-in", + "prefix": "foreach", "body": "for ${1:i} in ${3:\"\\${${2:array}[@]\\}\"}; do\n\t$4\ndone$0", "description": "Bash snippet 'foreach'" }, + "argv": { + "prefix": "argv", + "body": "\"\\$@\"$0", + "description": "Bash snippet 'argv'" + }, + "foreach-hashmap": { + "prefix": "foreach-hashmap", + "body": "local ${1:key} ${2:val}\nfor ${1:key} in \"\\${!${3:array}[@]\\}\"; do\n\t${2:val}=\"\\${${3:array}[\"\\$${1:key}\"]}\"\n\t${4:BODY}\ndone$0", + "description": "Bash snippet 'foreach-hashmap'" + }, "for-range": { "prefix": "for-range", "body": "for ${1:i} in ${4:{${2:1}..${3:10}\\}}; do\n\t$5\ndone$0", @@ -62,17 +77,23 @@ }, "join-array": { "prefix": "join-array", - "body": "\"\\$(IFS=${1:\\$'\\n'}; printf \"%s\" \"\\${${2:arr}[*]}\")\"$0", + "body": "${3:\"}\\$(IFS='${1:-}'; printf \"%s\" \"\\${${2:arr}[*]}\")${3:\"}$0", "description": "Bash snippet 'join-array'" }, + "read-array": { + "prefix": "read-array", + "body": "local -a ${2:test}\nreadarray -d \\$'${3:\\n}' -t ${2:test} < <( ${4:CMD} )$0", + "description": "Bash snippet 'read-array'" + }, "variable": { "prefix": "var", + // "body": "${2:\"}\\$${3:{}$1${3:\\}}${2:\"}$0", // TODO: crashes zed "body": "${2:\"}\\${$1\\}${2:\"}$0", "description": "Bash snippet 'variable'" }, "subshell": { "prefix": "subshell", - "body": "\"\\$($1)\"$0", + "body": "\"\\$(${1:CMD})\"$0", "description": "Bash snippet 'subshell'" }, "subshell-multiline": { @@ -90,9 +111,19 @@ "body": "<<-\"${1:EOF}\"\n\t${2:BODY}\n${1:EOF}\n$0", "description": "Bash snippet 'heredoc'" }, - "has": { - "prefix": "has", + "printf": { + "prefix": "printf", + "body": "printf${2: >&${1:1}} '${3:%s}\\n' ${4:args}$0", + "description": "Bash snippet 'printf'" + }, + "echo": { + "prefix": "echo", + "body": "echo${2: >&${1:1}} \"${3}\"$0", + "description": "Bash snippet 'echo'" + }, + "command": { + "prefix": "command", "body": "command -v ${1:cmd} >/dev/null$0", - "description": "Bash snippet 'has'" + "description": "Bash snippet 'command'" } }