Jamie O Maguire
Jamie O Maguire

Reputation: 43

Changing the VSCode integrated shell's prompt on MacOS X

Having just installed VScode I have noticed as it uses Bash by default on OSX, with the shell's default prompt of bash-3.2$; consequently, I cannot see the current working directory. It means having to type 'pwd' and 'ls' quite frequently which is obvious quite tedious.

I have tried changing the default shell in the settings to

"terminal.integrated.shell.osx": "/Applications/Utilities/Terminal.app" 

or

"terminal.integrated.shell.osx": "/Applications/iTerm.app"

This doesn't seem to work, have I made a mistake here?

I would also like to know if I am limited to bash, can I configure it to display the working directory instead of simply bash-3.2$ ?

See this screenshot of how the VSCode integrated terminal looks by default Thanks in advance!

Upvotes: 4

Views: 5270

Answers (2)

4ndt3s
4ndt3s

Reputation: 3467

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

if [ "$TERM_PROGRAM" = "vscode" ]; then
  PS1='\$ '
fi

Try it and let me know if it works on your OS.

Upvotes: 2

Greg Tarsa
Greg Tarsa

Reputation: 1642

You can set your prompt to contain the current working directory by defining PS1 as follows:

PS1="\w $"

The $ is just some visual sugar. There all manner of things you can have your prompt display. Put the definition in your ~/.bashrc or ~/.profile for it to be set when you login.

Check out the Controlling the Prompt section of the GNU Bash manual for details.

If you are not accustomed to editing your bash init files you can do it with Visual Studio Code by going to View->Command Palette and execute the following command (one-time only):

Install 'Code' command in path

Then open the integrated terminal and type the following:

code ~/.bashrc

Then add the PS1 definition to the bottom of that file.

Upvotes: 1

Related Questions