Changing the VSCode integrated shell's prompt on MacOS X

為{幸葍}努か 提交于 2019-12-11 02:29:04

问题


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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/42042557/changing-the-vscode-integrated-shells-prompt-on-macos-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!