1. 3
    Customize the PS1 Bash/Zsh Command Prompt in VS Code with Environment Variables
    1m 31s

Customize the PS1 Bash/Zsh Command Prompt in VS Code with Environment Variables

Xiaoru Li
InstructorXiaoru Li
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 4 years ago

In this lesson, we will learn how to use custom ENV variables to customize the PS1 Bash/Zsh command prompt in the VS Code terminal, without affecting our custom terminal themes in other applications. We will see how this can be useful for keeping the terminal clean for screen recordings.

I'm using Zsh in this video, but this works in Bash with ~/.bashrc as well.

Xiaoru Li: [00:00] I use zsh in my terminal and have configured my command prompt with all my zsh themes and plugins to be colorful and full of useful information. This is a nice setup for data use but can be very destructing for the audience if I use this to teach and to record screencasts.

[00:20] To clear up all the symbols and information only in VS Code, but not globally system-wide, we can go to settings, and add a custom environment's variable. I am using MacOS, so I am going to add a new property, terminal.integrated.env.osx, and a new variable which will run a value.

[00:43] This way, when a new terminal respond inside VS Code, zsh can pick up this custom environment variable and realize that it's in VS Code, but not in external standalone terminals like iTerm2.

[00:55] Now, let's open our zsh resource file, zshrc and add a simple check at the end of the file to handle the case when the terminal is open in VS Code.

[01:06] Let's set the PS1, the prompt itself to a single $ sign and a space. Now we can save and reload everything, then test it out.

[01:18] As you can see, the command prompt is now a $ sign in the VS Code terminal, but I still have the fancy setup in iTerm2.