Skip to content
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

Add snippets for argument parsing and fix case snippet #937

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions server/src/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,49 @@ export const SNIPPETS: BashCompletionItem[] = [
label: 'device',
insertText: '/dev/${1|null,stdin,stdout,stderr|}',
},
{
label: 'parse',
documentation: 'option parsing',
insertText: [
'while getopts "hv${1:single-letter-options}" ${2:option}; do',
'\tcase "\\$$2" in',
'\t\th)',
'\t\t\t${3:command for -h option ...}',
'\t\t\t;;',
'\t\tv)',
'\t\t\t${4:command for -v option ...}',
'\t\t\t;;',
'\t\t*)',
'\t\t\t${5:command ...}',
'\t\t\t;;',
'\tesac',
'done',
].join('\n'),
},
{
label: 'manual-parse',
documentation: 'manual option parsing',
insertText: [
'while [[ -n "\\$1" ]]; do',
'\tdeclare ${1:option}="\\$1"',
'\tdeclare ${2:argument}="\\$2"',
'\t',
'\tcase "\\$$1" in',
'\t\t-h|--help)',
'\t\t\t${3:command for -h/--help option ...}',
'\t\t\t;;',
'\t\t-v|--version)',
'\t\t\t${4:command for -v/--version option ...}',
'\t\t\t;;',
'\t\t*)',
'\t\t\t${5:command ...}',
'\t\t\t;;',
'\tesac',
'\t',
'\tshift',
'done',
].join('\n'),
},
{
documentation: 'completion',
label: 'completion definition',
Expand Down
Loading