Skip to content

Instantly share code, notes, and snippets.

@maoueh
Last active June 21, 2019 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maoueh/40d8d3375e2c545795c6a9d4d9803326 to your computer and use it in GitHub Desktop.
Save maoueh/40d8d3375e2c545795c6a9d4d9803326 to your computer and use it in GitHub Desktop.
VS Code Shellscript Snippets for a Bash Boilerplate script (developer script)
{
"Bash script boilerplate": {
"prefix": "bshb",
"body": [
"#!/usr/bin/env bash",
"",
"ROOT=\"$( cd \"$( dirname \"\\${BASH_SOURCE[0]\\}\" )\" && pwd )\"",
"",
"main() {",
" current_dir=\"`pwd`\"",
" trap \"cd \\\"\\$current_dir\\\"\" EXIT",
" pushd \"\\$ROOT\" &> /dev/null",
"",
" $2=\"\\$1\"; shift",
"",
" if [[ \\$$2 == \"\" ]]; then",
" usage_error \"argument <$2> is required\"",
" fi",
"",
" echo \"Value: \\$$2\"",
"}",
"",
"usage_error() {",
" message=\"\\$1\"",
" exit_code=\"\\$2\"",
"",
" echo \"ERROR: \\$message\"",
" echo \"\"",
" usage",
" exit \\${exit_code:-1\\}",
"}",
"",
"usage() {",
" echo \"usage: $1 <$2>$0\"",
" echo \"\"",
" echo \"$3\"",
"}",
"",
"main \\$@",
],
"description": "Create a full Bash script boilerplate"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment