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?
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.
.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? –
Ezra .bash_profile
in user directory. Thank you for the information on $PS1
. Maybe you would like to edit your answer and include .bash_profile
? –
Ezra .bashrc
doesn't exist, you can create it. I will, however, edit my answer as suggested. –
Slaw .bashsc
had no effect, but when I tried to create .bash_profile
with the same content, it worked as suggested. –
Ezra .bashsc
? I assume that was a typo? Anyways, as I don't have a Mac I can't confirm this, so I'm just going to do as you said and replace all occurences of .bashrc
with .bash_profile
. –
Slaw Control
worked and Command
didn't when saving the file. –
Ergotism 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\] "
gallois
theme. (Check out my dotfiles for more information.) –
Ezra zsh
myself. –
Headsman 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. :)
© 2022 - 2024 — McMap. All rights reserved.