Skip to content

Releases: Nikolai2038/bash-ide-from-vs-code

v.1.1.0

11 Nov 19:05
Compare
Choose a tag to compare

Changes:

  • Automatically sort source commands on file change;
  • Update extensions list;
  • Fix typos.

v.1.0.0

01 Nov 17:37
Compare
Choose a tag to compare

bash-ide-from-vs-code

Instructions and extra files on how to set up VS Code as Bash/Shell scripts IDE.

1. Install VS Code

You know how to do it, right? Riiiight..?

Anyway, after installing/already having one, I recommend you to create separate profile and call it something fancy, for example, Bash IDE.
You can still install all the extensions in any or even all of your profiles, but be aware that most of the time when you will work on some, for example, Java project, you don't want to decrease your VS Code performance by running extra 10+ extensions you don't need right now.
Decide what is more comfy for you here.
For me - it is the separate profile.

2. Install language server

  • Arch Linux:

    sudo pacman --sync --refresh --needed bash-language-server

3. Install and configure main extensions

Below you will see descriptions and reasons to install each extension.
Also, the JSON provided is the VS Code settings I used to configure each extension.
If some settings are not provided, that means I left them with default.

Also, if you have suggestions and advices, feel free to add them via issues or pull requests!

You can also skip all the instructions below - just install all the references extensions and merge content of settings.json into your VS Code settings.

3.1. Bash IDE

This is main extension which gives us language server.

// Follow redirection operators with a space (more readable)
"bashIde.shfmt.spaceRedirects": true,
// Increase number of files to analize (analize them all to not miss any reference to show)
"bashIde.backgroundAnalysisMaxFiles": 9999,
// Decrease logging level
"bashIde.logLevel": "warning",
// Disable "shellcheck" from Bash IDE - it is not working properly for some reason - and to not download anything in system - use "ShellCheck" extension instead with bundled command
"bashIde.shellcheckPath": "",
// Disable "shfmt" from Bash IDE - to not download anything in system - use "shell-format" extension instead with bundled command
"bashIde.shfmt.path": "",

3.2. File Watcher

This extension allow us to execute custom scripts on file changes.
We use it to update all links to the file and from the file to other files.

// Run custom script on file rename, which will update all links to this files from other files, and all links from this file to others
"filewatcher.commands": [
    {
        "event": "onFileRename",
        "match": ".*\\.sh",
        "cmd": "/usr/bin/rename_or_move_shell_script \"${workspaceRoot}\" \"${fileOld}\" \"${file}\""
    }
],

I wrote the script rename_or_move_shell_script.sh do do all the renames and put it in this repository.
You can install it by running:

sudo wget -O /usr/bin/rename_or_move_shell_script https://raw.githubusercontent.com/Nikolai2038/bash-ide-from-vs-code/refs/heads/main/rename_or_move_shell_script.sh && \
sudo chmod +x /usr/bin/rename_or_move_shell_script

On how the script works - you can check by yourself.
If you found a bug or have a suggestion on how to optimize it, you will be the awesome man to let me know something that will make it better!

3.3. Path Intellisense

This extension will autocomplete relative paths to scripts when you entering them in source, find, etc.

3.4. ShellCheck

This extension will lint all the problems in your code.
This can be also done with Bash IDE extension, but when I used it, it was not working properly - in my case some shell variable was declared as not declared, but it was - in anohter file, and sourced. With the ShellCheck extension this problem does not replicate.

// Decrease logging level
"shellcheck.logLevel": "warn",
// Parse external files in "source" command
"shellcheck.customArgs": [
    "--external-sources"
],
// Reduce CPU usage - we will use autosave anyway
"shellcheck.run": "onSave",

3.5. shell-format

This extension will autoformat code.
You can play with flags as you want, I leave here the ones I use.
You can also disable format on save if you want or when you are working on already written scripts and don't want all file to change.

// Flags for formatting:
// -s,  --simplify  simplify the code
// -i,  --indent uint       0 for tabs (default), >0 for number of spaces
// -bn, --binary-next-line  binary ops like && and | may start a line
// -ci, --case-indent       switch cases will be indented
// -sr, --space-redirects   redirect operators will be followed by a space
// -kp, --keep-padding      keep column alignment paddings
// -fn, --func-next-line    function opening braces are placed on a separate line
"shellformat.flag": "--simplify --indent 2 --binary-next-line --case-indent --space-redirects",
// Autoformat
"[shellscript]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "foxundermoon.shell-format"
},

3.6. TypeLens

This will show useful links above function declarations.
You can localize them for your language.
I use English:

"typelens.noreferences": "No references found",
"typelens.plural": "{0} references",
"typelens.singular": "{0} reference",

3.7. Shell Script Command Completion

This extension is awesome - it provides suggestions for shell commands when you write them in your script.

3.7. Bash Debug

To debug Bash scripts.

3.8. Code Runner

Run shell script with the button.

3.9. shellman

Useful shell snippets.

3.10. Shebang Snippets

More snippets.

3.11. Sort lines

Useful to sort source commands.

TODO: This can be implemented automatically with script in File Watcher extension.

3. (Optional) Install and configure extra extensions

3.1. GIT

  • GitLens — Git supercharged - It will bring more views to play with. I don't use paid version. For git log use Git Graph extension below. Config:

    "gitlens.codeLens.enabled": false,
    "gitlens.currentLine.enabled": false,
    "gitlens.showWelcomeOnInstall": false,
    "gitlens.statusBar.enabled": false,
    "gitlens.telemetry.enabled": false,
  • Git Graph - Git log. Config I use:

    "git-graph.commitDetailsView.location": "Docked to Bottom",
    "git-graph.date.format": "ISO Date & Time",
    "git-graph.dialog.addTag.pushToRemote": true,
    "git-graph.dialog.addTag.type": "Lightweight",
    "git-graph.dialog.cherryPick.recordOrigin": true,
    "git-graph.referenceLabels.combineLocalAndRemoteBranchLabels": false,
  • Gitignore Ultimate - .gitignore file autocompletion;

  • Git History - Views with history of changes in line, file;

  • git-autoconfig - Useful, if you have several accounts to commit from (work, for example). Otherwise, not needed. Extra setting:

    // Run only on workspace start, not in background every 5 seconds
    "git-autoconfig.queryInterval": 999999999,

Extra git settings I use:

"git.confirmSync": false,
"git.autofetch": true,
"git.enableSmartCommit": true,
"diffEditor.ignoreTrimWhitespace": false,
// Don't find repositories automatically (because it bother, when working not in repositories)
"git.autoRepositoryDetection": false,
// Always open GIT repository in parent folders
"git.openRepositoryInParentFolders": "always",
"git.replaceTagsWhenPull": true,

3.2. Markdown

3.3. Useful

Read more