From 2bc7cd7ac0990386727af6b8f437e3aedd730f89 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 9 Aug 2023 17:35:06 +1000 Subject: [PATCH 1/3] feat(snippet): support argument parsing --- server/src/snippets.ts | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index 2730fc1f..f6911fbb 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -639,6 +639,49 @@ export const SNIPPETS: BashCompletionItem[] = [ label: 'device', insertText: '/dev/${1|null,stdin,stdout,stderr|}', }, + { + label: 'option-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: 'option-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', From 0d649426853de815bfba77440d47f0d40fc8cd20 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 9 Aug 2023 17:35:22 +1000 Subject: [PATCH 2/3] fix(snippet): case snippet --- server/src/snippets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index f6911fbb..b7622f16 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -459,7 +459,7 @@ export const SNIPPETS: BashCompletionItem[] = [ '\t*)', '\t\t${4:command ...}', '\t\t;;', - 'end', + 'esac', ].join('\n'), }, { From d6d4a238025185077423a9f9d4b328201ea1f1ab Mon Sep 17 00:00:00 2001 From: Emily Grace Seville Date: Wed, 9 Aug 2023 18:09:02 +1000 Subject: [PATCH 3/3] feat(snippets): make labels more concise --- server/src/snippets.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index b7622f16..ef4425b7 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -640,7 +640,7 @@ export const SNIPPETS: BashCompletionItem[] = [ insertText: '/dev/${1|null,stdin,stdout,stderr|}', }, { - label: 'option-parse', + label: 'parse', documentation: 'option parsing', insertText: [ 'while getopts "hv${1:single-letter-options}" ${2:option}; do', @@ -659,7 +659,7 @@ export const SNIPPETS: BashCompletionItem[] = [ ].join('\n'), }, { - label: 'option-manual-parse', + label: 'manual-parse', documentation: 'manual option parsing', insertText: [ 'while [[ -n "\\$1" ]]; do',