-
Notifications
You must be signed in to change notification settings - Fork 131
Bash: Add snippets for VS Code #664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3962e3c
728c362
cfba66f
03382a2
b7f3d76
85bcde4
24f5ce3
2076714
5319cd1
1c8d7e6
e3a7ba7
9edc28b
7a49911
4e97c0a
8e56a40
b386a82
65021b0
1bc5a0d
f10bcbc
ea06f10
4e7745c
1e7f641
1e17a6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Snippet naming convention | ||
|
||
- Snippet name always language keyword, builtin name or expansion symbol like `:-`. | ||
- `description` always a short snippet explanation without leading articles and trailing punctuation. | ||
Mnemonics with square brackets are always used to denote what chars are included in snippet `prefix`. | ||
- `prefix` can be just a string or array containing two item. The string or first item always follow these rules: | ||
- If a snippet is for language construct then first two letters of the first word from `description` are used | ||
plus the first letter from the second one (if it's exist). | ||
- If a snippet is for a builtin then builtin name is used. | ||
- If a snippet is for expansion then expansion symbol is used. | ||
- If a snippet is for a specific external program like **awk** then program name must be added to `prefix` like this: | ||
`awk:{{snippet-prefix}}`. | ||
The second one is always a noun existing to make snippets more memorizable. | ||
- `body` is always array. | ||
- If both short and long options available placeholder must be used to let user to chose the option's style | ||
but the first alternative should always be the long option. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
{ | ||
"shebang": { | ||
"description": "[sh]hebang", | ||
"prefix": "shebang", | ||
"body": [ | ||
"#!/usr/bin/env ${1|bash,sh|}" | ||
] | ||
}, | ||
"if": { | ||
"description": "[if]", | ||
"prefix": "if", | ||
"body": [ | ||
"if ${1:command}; then", | ||
"\t$0", | ||
"fi" | ||
] | ||
}, | ||
"if-else": { | ||
"description": "[if] [e]lse", | ||
"prefix": "if-else", | ||
"body": [ | ||
"if ${1:command}; then", | ||
"\t${2:echo}", | ||
"else", | ||
"\t$0", | ||
"fi" | ||
] | ||
}, | ||
"while": { | ||
"description": "[wh]ile", | ||
"prefix": "while", | ||
"body": [ | ||
"while ${1:command}; do", | ||
"\t$0", | ||
"done" | ||
] | ||
}, | ||
"until": { | ||
"description": "[un]til", | ||
"prefix": "until", | ||
"body": [ | ||
"until ${1:command}; do", | ||
"\t$0", | ||
"done" | ||
] | ||
}, | ||
"for": { | ||
"description": "[fo]r", | ||
"prefix": "for", | ||
"body": [ | ||
"for ${1:variable} in ${2:list}; do", | ||
"\t$0", | ||
"done" | ||
] | ||
}, | ||
"function": { | ||
"description": "[fu]nction", | ||
EmilyGraceSeville7cf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"prefix": "function", | ||
"body": [ | ||
"${1:function_name}() {", | ||
"\t$0", | ||
"}" | ||
] | ||
}, | ||
"main": { | ||
"description": "[ma]in", | ||
"prefix": "main", | ||
"body": [ | ||
"main() {", | ||
"\t$0", | ||
"}" | ||
] | ||
}, | ||
":-": { | ||
"description": "[:-] expansion", | ||
"prefix": ":-", | ||
"body": [ | ||
"\"\\${${1:variable}:-${2:default}}\"" | ||
] | ||
}, | ||
":=": { | ||
"description": "[:=] expansion", | ||
"prefix": ":=", | ||
"body": [ | ||
"\"\\${${1:variable}:=${2:default}}\"" | ||
] | ||
}, | ||
":?": { | ||
"description": "[:?] expansion", | ||
"prefix": ":?", | ||
"body": [ | ||
"\"\\${${1:variable}:?${2:error_message}}\"" | ||
] | ||
}, | ||
":+": { | ||
"description": "[:+] expansion", | ||
"prefix": ":+", | ||
"body": [ | ||
"\"\\${${1:variable}:+${2:alternative}}\"" | ||
] | ||
}, | ||
"#": { | ||
"description": "[#] expansion", | ||
"prefix": "#", | ||
"body": [ | ||
"\"\\${${1:variable}#${2:pattern}}\"" | ||
] | ||
}, | ||
"##": { | ||
"description": "[##] expansion", | ||
"prefix": "##", | ||
"body": [ | ||
"\"\\${${1:variable}##${2:pattern}}\"" | ||
] | ||
}, | ||
"%": { | ||
"description": "[%] expansion", | ||
"prefix": "%", | ||
"body": [ | ||
"\"\\${${1:variable}%${2:pattern}}\"" | ||
] | ||
}, | ||
"%%": { | ||
"description": "[%%] expansion", | ||
"prefix": "%%", | ||
"body": [ | ||
"\"\\${${1:variable}%%${2:pattern}}\"" | ||
] | ||
}, | ||
"..": { | ||
"description": "brace expansion", | ||
"prefix": "..", | ||
"body": [ | ||
"{${1:from}..${2:to}}" | ||
] | ||
}, | ||
"echo": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how much value very basic snippets like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to save some keystrokes and quote argument automatically. :) |
||
"description": "[echo]", | ||
"prefix": "echo", | ||
"body": [ | ||
"echo \"${1:message}\"" | ||
] | ||
}, | ||
"printf": { | ||
"description": "[printf]", | ||
"prefix": "printf", | ||
"body": [ | ||
"printf '%s' \"${1:message}\"" | ||
] | ||
}, | ||
"source": { | ||
"description": "[source]", | ||
"prefix": "source", | ||
"body": [ | ||
"source \"${1:path/to/file}\"" | ||
] | ||
}, | ||
"alias": { | ||
"description": "[alias]", | ||
"prefix": "alias", | ||
"body": [ | ||
"alias ${1:name}=${2:value}" | ||
] | ||
}, | ||
"cd": { | ||
"description": "[cd]", | ||
"prefix": "cd", | ||
"body": [ | ||
"cd \"${1:path/to/directory}\"" | ||
] | ||
}, | ||
"getopts": { | ||
"description": "[getopts]", | ||
"prefix": "getopts", | ||
"body": [ | ||
"getopts ${1:optstring} ${2:name}" | ||
] | ||
}, | ||
"jobs": { | ||
"description": "[jobs]", | ||
"prefix": "jobs", | ||
"body": [ | ||
"jobs -x ${1:command}" | ||
] | ||
}, | ||
"kill": { | ||
"description": "[kill]", | ||
"prefix": "kill", | ||
"body": [ | ||
"kill ${1|-l,-L|}" | ||
] | ||
}, | ||
"let": { | ||
"description": "[let]", | ||
"prefix": "let", | ||
"body": [ | ||
"let ${1:argument}" | ||
] | ||
}, | ||
"test": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"description": "[test]", | ||
"prefix": "test", | ||
"body": [ | ||
"[[ ${1:argument1} ${2|-ef,-nt,-ot,==,=,!=,=~,<,>,-eq,-ne,-lt,-le,-gt,-ge|} ${3:argument2} ]]" | ||
] | ||
}, | ||
"stream": { | ||
"description": "[de]vice name", | ||
"prefix": "dev", | ||
"body": [ | ||
"/dev/${1|null,stdin,stdout,stderr|}" | ||
] | ||
}, | ||
"sed:filter-lines": { | ||
"description": "[sed:filter-lines]", | ||
"prefix": "sed:filter-lines", | ||
"body": [ | ||
"sed ${1|--regexp-extended,-E|} ${2|--quiet,-n|} '/${3:pattern}/' ${4:path/to/file}" | ||
] | ||
}, | ||
"awk:filter-lines": { | ||
"description": "[awk:filter-lines]", | ||
"prefix": "awk:filter-lines", | ||
"body": [ | ||
"awk '/${1:pattern}/' ${2:path/to/file}" | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice with this documentation. Once the snippets are in TypeScript, then we should change this markdown file to some unit tests to ensure that this is enforced.