akl
akl

Reputation: 107

How to customize the shell prompt in the VS Code terminal on macOS

I'm trying to customize my integrated terminal shell prompt in vscode, and was successfully able to change the theme (so that I can see my current working directory and branch I'm on), however now I want to remove the first portion 'anhlucci@Anhs-MacBook-Pro'. How do I do that?

enter image description here

Upvotes: 4

Views: 9142

Answers (2)

4ndt3s
4ndt3s

Reputation: 3467

I use Ubuntu with bash, and I only add the following lines to the end of ~/.bashrc:

if [ "$TERM_PROGRAM" = "vscode" ]; then
  PS1='\[\033[01;34m\]\w\[\033[00m\]\$ '
fi

I found that vscode sets TERM_PROGRAM environment variable, and then use it to modify PS1 only to vscode.

Upvotes: 12

Hongli
Hongli

Reputation: 18924

The command line prompt is not dictated by Visual Studio Code, but by bash. The prompt is dictated by the PS1 variable in bash. You can view it as follows:

echo "$PS1"

To give you an idea of how that works, this is how my prompt looks like:

[hongli@Leticia Projects]$

My $PS1 looks like this:

[\u@\h \W]\$

Things like \u and \h are formatters that are substituted with a specific value. \u is for the current username, \h is for the hostname.

I'm guessing your $PS1 contains something like \u@\h in the beginning. Remove that and reset the PS1 variable, for example like this:

PS1='[\W]\$ '

Finally, you need to persist this in your bash configuration file so that the next time you start your shell it will show that same prompt. The bash config file is typically ~/.bashrc or ~/.profile depending on the exact Linux distribution you use. Make sure you set $PS1 in there.

Upvotes: 3

Related Questions