I have started writing some bash scripts to augment git, using Visual Studio Code and I want the editor to use syntax highlighting when doing so.
The files do not have an extension, or git won't pick them up as additional commands.
Here's an example name of such a script: git-review
So the question is, how can I configure Visual Studio Code to use Bash syntax highlighting for these files?
If I rename the file from inside Visual Studio Code to something with .sh
, like git-review.sh
and then back to no extension (git-review
), Visual Studio Code seems to remember this and show syntax highlighting but any new files I add to the folder is highlighted as plain text (until I do the renaming dance). Visual Studio Code seems to remember this even if I close the file and restart Visual Studio Code and reopen the file. For how long I do not know.
I can live with plain text files that for some reason doesn't have an extension being highlighted as bash scripts, but obviously, if there is a way to make Visual Studio Code even smarter, like looking at the first line for #!/bin/sh
then that would be even better.
I tried using the "Configure file association for '.xyz'" to see how these associations were stored in the settings file and found that this correctly applies Bash highlighting to .xyz
files:
"files.associations": {
"*.xyz": "shellscript"
},
However, this does not:
"files.associations": {
"*.": "shellscript"
},
nor does this:
"files.associations": {
"*": "shellscript"
},
Is there any way to coax this setting into working for extensionless files?
This is Visual Studio Code for Windows if that matters at all.
There is no simple way to obtain syntax highlighting in GNU Bash (or GNU Readline), but it is in principle possible to implement your own line editor in Bash script by binding all the user inputs to shell functions using the builtin command bind -x 'BYTE: SHELL-COMMAND' .
VS Code provides excellent extensions for Bash scripting. In this article, we will cover a built-in shell extension, a linter, a formatter, a snippet extension, a debugger, and more.
if there is a way to make Visual Studio Code even smarter, like looking at the first line for
#!/bin/sh
then that would be even better.
VSCode actually already does assoicate files with shellscript
based on the shebang. However, note that it doesn't detect it dynamically - if you add a shebang, you will need to close and reopen the file for VSCode to notice it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With