Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 958
Jamie O Maguire Avatar asked Oct 20 '25 16:10

Jamie O Maguire


2 Answers

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.

like image 58
4ndt3s Avatar answered Oct 23 '25 08:10

4ndt3s


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.

like image 28
Greg Tarsa Avatar answered Oct 23 '25 08:10

Greg Tarsa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!