1

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

Mark
  • 143,421
  • 24
  • 428
  • 436
akl
  • 77
  • 3
  • 9
  • This might help: https://stackoverflow.com/questions/52107170/hiding-the-full-file-path-in-a-powershell-command-prompt-in-vscode/52107556#52107556 although it is Windows/Powershel-centric but it might give you some clues about where to look.l – Mark Jan 25 '19 at 15:29
  • https://stackoverflow.com/questions/42042557/changing-the-vscode-integrated-shells-prompt-on-macos-x and https://superuser.com/questions/1348068/how-can-i-hide-the-macbook-name-and-path-name-in-terminal-initial-line and https://askubuntu.com/questions/16728/hide-current-working-directory-in-terminal – Mark Jan 25 '19 at 15:44

2 Answers2

9

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.

4ndt3s
  • 3,238
  • 2
  • 20
  • 30
3

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.

Hongli
  • 18,682
  • 15
  • 79
  • 107