From 37b0e54e986fd694e8878714e7b6a07c35b8d2f2 Mon Sep 17 00:00:00 2001 From: AndreaMontalbani Date: Sat, 14 Dec 2024 20:47:32 +0100 Subject: [PATCH 1/2] =?UTF-8?q?-=20Rename=20array=20snippets=20for=20clari?= =?UTF-8?q?ty=20(forarray=20=E2=86=92=20forarre,=20forindex=20=E2=86=92=20?= =?UTF-8?q?forrange)=20-=20Add=20new=20snippets=20for=20case=20statements?= =?UTF-8?q?=20and=20while=20loops=20-=20Add=20array=20indexing=20helper=20?= =?UTF-8?q?snippet=20-=20Fix=20array=20loop=20descriptions=20and=20simplif?= =?UTF-8?q?y=20range=20iteration=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snippets/snippets.code-snippets | 45 ++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/snippets/snippets.code-snippets b/snippets/snippets.code-snippets index a5b347d..c3c526a 100644 --- a/snippets/snippets.code-snippets +++ b/snippets/snippets.code-snippets @@ -110,23 +110,56 @@ ], "description": "Creates an array with two elements" }, - "forarray": { - "prefix": "forarray", + "forarre": { + "prefix": "forarre", "body": [ "for ${0:element} in \\${${MYARRAY}[@]\\}; do", "echo \\$${0:element}", "done" ], - "description": "Creates a loop echoing all variables in an array" + "description": "Creates a loop echoing all elements in an array" }, - "forindex": { - "prefix": "forindex", + "forrange": { + "prefix": "forrange", "body": [ "for ${0:i} in {${1:0}..${2:5}\\}; do", "echo \\$${0:i}", - "echo \\${MYARRAY[${0:i}]}", "done" ], "description": "Creates a loop echoing all indexes in a range" + }, + "case": { + "prefix": "case", + "body": [ + "case ${1:expression} in", + "${2:patt_1})", + " STATEMENTS", + " ;;", + "${3:patt_2})", + " STATEMENTS", + " ;;", + "*)", + " STATEMENTS", + " ;;", + "esac" + ], + "description": "Creates a case statement" + }, + "arri": { + "prefix": "arri", + "body": [ + "${${1:myArray}[${2:i}]}" + ], + "description": "Array indexing statement" + }, + "while": { + "prefix": "while", + "body": [ + "while [ ${1:condition} ]", + "do", + " ${2:echo hi}", + "done" + ], + "description": "Array indexing statement" } } From ceb59c4dc857f0b2cc3efad2eb37347809c71ef9 Mon Sep 17 00:00:00 2001 From: AndreaMontalbani Date: Sat, 14 Dec 2024 20:48:16 +0100 Subject: [PATCH 2/2] Documented changes and added backtick around snippet prefixes in the documentation --- CHANGELOG.md | 15 ++++++++++++++ README.md | 55 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25bba17..90e873c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,3 +27,18 @@ Additionally it added the following new snippets: - main : main - const : const - todo : TODO + +### [1.0.1] + +`forrange` snippet: + Removed the line using the index to reference the index of an array as it is not strictly part of the snippet, `arri` was introduced for that purpose. + +Documented the following snippets, that were previously implemented, some of them under different names (name changes reported below): +- `array` : declares an array +- `forarray` -> `forarre` : iterates throught the elements in an array +- `forindex` -> `forrange` : iterates throught a range of indexes + + +Added the following new snippet: +- `case`: shell case statement +- `arri`: Array indexing statement \ No newline at end of file diff --git a/README.md b/README.md index 7c9b2d4..bc92710 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,22 @@ A collection of bash snippets Just a few snippets to make shellscript dev easier -- shebang : shebang -- e : echo -- fn : function -- fnd : function with definitions -- if : if -- ife : if else -- elif : elif -- until : until -- main : main -- const : const -- todo : TODO +- `shebang` : shebang +- `e` : echo +- `fn` : function +- `fnd` : function with definitions +- `if` : if +- `ife` : if else +- `elif` : elif +- `until` : until +- `main` : main +- `const` : const +- `todo` : TODO +- `array` : array declaration +- `forarre` : iterates throught the elements in an array +- `forrange` : iterates throught a range of indexes +- `case`: shell case statement +- `arri`: Array indexing statement ## Known Issues @@ -26,13 +31,13 @@ None ### 0.0.1 -- shebang : shebang -- e : echo -- fn : function -- if : if -- ife : if else -- elif : elif -- until : until +- `shebang` : shebang +- `e` : echo +- `fn` : function +- `if` : if +- `ife` : if else +- `elif` : elif +- `until` : until ### 0.0.2 @@ -43,9 +48,15 @@ Added a logo This release updated the format choice for function names (fn) to align with the [Shell Style Guide](https://google.github.io/styleguide/shellguide.html#function-comments) Additionally it added the following new snippets: -- fnd : function with definitions -- main : main -- const : const -- todo : TODO +- `fnd` : function with definitions +- `main` : main +- `const` : const +- `todo` : TODO + +### 1.0.1 + +Added the following new snippet: +- `case`: shell case statement +- `arri`: Array indexing statement **Enjoy!**