diff --git a/server/src/snippets.ts b/server/src/snippets.ts index 5f471805..40a74b0f 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -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',