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?
-
Also see: apple.stackexchange.com/a/224151/54395– NakilonCommented Aug 7, 2016 at 0:12
4 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.
-
1Thanks for help. But I can't find
.bashrc
on my machine. I've heard a lot about it before, like changing$PATH
with it, etc., but it never existed. And creating it wouldn't help—I created it, loggout out and back in, but nothing changed. Maybe there is another file in control on OS X 10.8?– 4ae1e1Commented Jan 19, 2013 at 18:37 -
1I managed to succeed by creating
.bash_profile
in user directory. Thank you for the information on$PS1
. Maybe you would like to edit your answer and include.bash_profile
?– 4ae1e1Commented Jan 19, 2013 at 18:46 -
2Actually what I said is that creating
.bashsc
had no effect, but when I tried to create.bash_profile
with the same content, it worked as suggested.– 4ae1e1Commented Jan 20, 2013 at 1:43 -
3Yeah, sorry that was a typo... OS X is somewhat different from Linux you know. Most annoyingly, every major release of OS X itself is somewhat different in handling these kinds of stuffs :( They are enhancing accessibility for dummies and as a result, they are hiding a lot of things to prevent dummies from playing around with.– 4ae1e1Commented Jan 20, 2013 at 18:40
-
1
Here's an excellent article with a full list of Variables and Colors:
Customize your Shell Command Prompt
For a simple, minimalistic prompt, you can try this. Add the following line to your .bash_profile
or simply test it first by running it in your terminal:
export PS1="\[\033[0m\]\w\$ "
It'll look something like this:
Here's my Prompt (source), also very simple:
export PS1="\[\033[1;97m\]\u: \[\033[1;94m\]\w \[\033[1;97m\]\$\[\033[0m\] "
-
1Thanks. The question was from more than one year ago. Now I use oh-my-zsh for themes (prompt and more) — personally, I use the
gallois
theme. (Check out my dotfiles for more information.)– 4ae1e1Commented Apr 18, 2014 at 3:52 -
@KevinSayHi Yeah, I posted it here so it could be helpful to others as well. Also, very nice - I was thinking of switching to
zsh
myself. Commented Apr 18, 2014 at 4:01 -
2Z Shell is really nice. Definitely give it try. There's no way back once you've made the switch (just like the Windows to OS X switch)!– 4ae1e1Commented Apr 18, 2014 at 4:17
2019 onwards, MacOS default shell is Z Shell. To customize command prompt, add a file named .zshrc
in user home and put following line that sets a PS1
environment variable with desired prompt format:
export PS1="[%n]%~> "
This is result of following format expansion:
%n
User name%~
Current directory
See full list of available expansions here.
Your answer can be found right here:http://www.hypexr.org/bash_tutorial.php#vi at about the middle of the page. :)
-
9Your answer would be more helpful if you described the solution here.– kukidoCommented Jan 8, 2014 at 23:08
-
The link given is misleading. The appropriate link would be hypexr.org/bash_tutorial.php#cmd_prompt. Don't create link-only answers, instead summarize the content in case the link rots and breaks. Commented Mar 21, 2016 at 17:55