Question is as stated in the title.
In gist, I am trying to get my bash scripts and Vim to behave differently when running in VS Code's integrated terminal.
I have managed to find several other Stack Overflow questions, but they relate to detection of operating systems:
- How to check if running in Cygwin, Mac or Linux?
- How to detect the OS from a Bash script?
Open Visual Studio Code and press and hold Ctrl + ` to open the terminal. Open the command palette using Ctrl + Shift + P . Type - Select Default Shell . Select WSL Bash (NOT Git Bash ) from the options.
To run or debug a simple app in VS Code, select Run and Debug on the Debug start view or press F5 and VS Code will try to run your currently active file.
So, here’s how to set up Vim in VS code and what commands you should know. — and don’t worry, you won’t get lost. The advantage of the VS Code extension is that you can use Vim, but you don’t have to. Have fun!
To enable the integrated shell, just use the ctrl +` keyboard shortcut (that’s control backtick, not apostrophe). This should launch your default shell. If you’re on Windows, this will be a standard command prompt, but you can adjust it to use Powershell or even Bash if you’d like.
Test your shell directly. Try running your designated integrated terminal shell outside VS Code from an external terminal or command prompt. Some terminal launch failures may be due to your shell installation and are not specific to VS Code.
For this, all you have to do is to run the following command from the editor: and type 'exit' when you are done with the shell work - this will bring you back into the Vim session from where you left initially. While the ability to access a shell definitely has its own uses in real world, it can also be used as a privilege escalation technique.
By examining the shell variables in the vscode terminal you can see that it sets TERM_PROGRAM=vscode
. In my .bash_profile I have the following and it works great:
if [ "$TERM_PROGRAM" == "vscode" ]; then
# some stuff
else
# other stuff
fi
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