Search code examples
bashshellvimvisual-studio-codezsh

How to check whether shell scripts / Vim running in VS Code integrated terminal?


Issue

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.

Things I've found

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?


Solution

  • 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