Skip to content

L13/vscode-sh-snippets

Repository files navigation

Shell Script Snippets

This extension contains keyword snippets and micro patterns for shell script.

What's new in Shell Script Snippets 0.16.0

  • Added l13Snippets.shellScript.useFunctionBlockPadding to enable or disable line padding in function blocks.

Index

  1. Introduction
  2. Shortcut rules for Shell Script
  3. Recommended Settings
  4. Recommended Keyboard Shortcuts
  5. Recommended Extensions

Introduction

The idea of those snippets is to create a workflow with micro patterns. Write one to four characters and you get the keyword or pattern.

Some prefixes are twice, because the rules are matching different patterns like e1 -> echo ; and export ;. Then you have to pick the right one.

The following prefixes are just examples to explain the rules. To see the complete list, please visit SNIPPETS.md. If a keyword or pattern might be missing, please open an issue on Github and make a suggestion.

Shortcut rules for Shell Script

1. The first letter of a word or the upper case in camel or pascal case defines the prefix.

Prefix Snippet
n null
f false
t true
itf if CONDITION; then ... fi
wdd while CONDITION; do ... done

2. An underscore "_" defines a value or subshell.

Prefix Snippet
_ "${}"
__ "$()"

3. An underscore "_" after a character defines a brace scope.

Prefix Snippet
f_ function NAME { ... }
$_ NAME () { ... }

4. The number "1" at the end defines a one line snippet.

Prefix Snippet
e1 echo ...;
s1 shift$0;

5. A case can be defined by the two following prefixes.

Prefix Snippet
_) ) ... ;;
_* *) ... ;;

6. A "b" or a "z" at the end stands for bash or zsh.

Prefix Snippet
s1b source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.sh";
s1z source "$(cd "$(dirname "${(%):-%x}")" && pwd)/.zsh";

7. A default pattern for a script can be initialized with

Prefix Snippet
$b #!/usr/bin/env bash main () { ... exit 0; };main "$@";
$z #!/usr/bin/env zsh main () { ... exit 0; };main "$@";

Recommended Settings

It is recommended to set the snippet suggestions to top.

"editor.snippetSuggestions": "top",

Recommended Keyboard Shortcuts

Please have the following keyboard shortcuts always in mind, because these are fundamental to get the most out of it. Every tab stop is used only if necessary, because it prevents VS Code to open the IntelliSense menu automatically. So sometimes DownArrow or Cmd/Ctrl + Enter can have the same effect.

macOS

  • Tab - Jump to the next tab stop of the snippet.
  • DownArrow - Move the caret down one line.
  • Cmd + Enter - Insert line below, even if the caret is in the middle of a line.
  • Cmd + Shift + Enter - Insert line above, even if the caret is in the middle of a line.

Windows / Linux

  • Tab - Jump to the next tab stop of the snippet.
  • DownArrow - Move the caret down one line.
  • Ctrl + Enter - Insert line below, even if the caret is in the middle of a line.
  • Ctrl + Shift + Enter - Insert line above, even if the caret is in the middle of a line.

Recommended Extensions