Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

macos - How to suppress (or customize) Mac Terminal shell prompt

Currently in my Terminal, every shell prompt looks like ComputerName: FooDir UserName$. The UserName part simply wastes too much space out of my precious 80 columns. Is there a way to suppress it?

question from:https://stackoverflow.com/questions/14416274/how-to-suppress-or-customize-mac-terminal-shell-prompt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The prompt is defined by the environment variable PS1 which you can define in .bash_profile.

To edit it, open or create the (hidden) file .bash_profile:

nano .bash_profile

and add a line that says

export PS1=""

Between the quotation marks, you can insert what you would like as your terminal prompt. You can also use variables there:

  • d – date
  • – time
  • h – hostname
  • # – command number
  • u – username
  • W – current directory (e.g.: Desktop)
  • w – current directory path (e.g.: /Users/Admin/Desktop)

The default prompt for common Linux distributions would be w $, which evaluates to ~ $ in your home directory or e.g. /Users $ somewhere else. There are also website (like this one) that can help you with building your prompt.

If you want to remove the UserName part, your choice would be h: w$.

Once you made your changes, save the file with Control+o, Return, Control+x.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...