✍️ Working on bash
[!INFORMATION] Disclaimer: This page is just one opinion. This is not the best way to work on bash scripts, this is just an explanation of how I work.
IDE
I work with VS code on windows + WSL.
Install VS code from here.
VS code extensions
Here is a list of recommended extensions to work on bash scripts:
- Bash IDE
- Debug bash scripts
- Shell Script Command Completion
- Better comments
- Better shellscript syntax
- Code spell checker
- EditorConfig
- Indent rainbow
- Format shell script
- Shellcheck
- Snippets manager
- Snippets for bash scripts
- Snippets for shebang
GitHub Copilot is of great help if you can have it. You can also find the list of extensions here.
VS code settings
You can open your ~/.valet.d
directory as a workspace on vscode.
Autocompletion on Valet library functions
You can use the Valet vscode snippets which should be generated locally using the valet self document
command.
Then:
- copy this file in your repository under the
.vscode
directory (you can chose to ignore this in git or push it). - or copy this file as
shellscript.json
in your user snippets folder (%APPDATA%\Code\User\snippets
in windows).
This allows you to have autocompletion and help on the core and libraries functions:
Autocompletion - alternative way
Alternatively, you copy (or link) the lib-valet file to ./lib-valet
. It is a file that defines all the function prototypes from Valet, allowing autocompletion with vscode bash IDE extension. It can be generated locally using the command valet self document
.
If you have installed the recommended extensions, you will also have shellcheck which will attempt to following the sourced files in your project. You should annotate each source
statement for shellcheck to use the lib-valet
file:
# shellcheck source=../lib-valet
source mylib
If you don’t want to use shellcheck, you can add the following settings in your ./.vscode/settings.json
:
{
"bashIde.globPattern": "**/@(*@(.sh|.inc|.bash|.command|core|main)|lib-*)",
"bashIde.includeAllWorkspaceSymbols": true
}