Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 710
4ae1e1 Avatar asked Jan 19 '13 16:01

4ae1e1


People also ask

How do I change zsh prompt on Mac?

To make any change to the default zsh prompt, you'll have to add relevant values for the prompt to appear differently than the default. It'll be blank if you're accessing it for the first time. You can add a new line with the text PROMPT='...' and include relevant values in the ellipses.

What is a shell prompt Mac?

The window contains a prompt that indicates you can enter a command. The prompt you see depends on your Terminal and shell preferences, but it often includes the name of the host you're logged in to, your current working folder, your user name, and a prompt symbol.


1 Answers

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
  • \t – 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.

like image 85
L3viathan Avatar answered Oct 06 '22 23:10

L3viathan