Change Terminal Prompt in Mac OS X
When you open a Terminal in Mac OS X, the default command prompt
displayed is a very long name which goes like this:
<ComputerName>:<CurrentDirectory> <UserName>$.
In my case it was Sunainas-MacBook-Pro:~ sunaina$, quite
boring!
I prefer something like sunaina@MacBook:~$, commonly used
in the Linux world. I did the following customizations.
-
On Terminal, execute the following commands.
sudo scutil --set ComputerName "MacBook" sudo scutil --set LocalHostName "MacBook" sudo scutil --set HostName "MacBook"
The
ComputerNameandLocalHostNameare also accessible asComputer NameandLocal Hostnamerespectively, atSystem Preferences > Sharing. TheComputerName,LocalHostNameandHostNameare saved in/Library/Preferences/SystemConfiguration/preferences.plist. -
Edit the file
~/.bash_profilewith the following command.mvim ~/.bash_profile
-
Add the following line to
~/.bash_profile, save and quit.export PS1="\u@\h:\w$ "
Here,
\ustands for the username of the current user.\hstands for the hostname upto the first '.'.\wstands the current working directory.
-
Open a new Terminal. You should see your customized prompt.
Play around with the prompt
escapes for the PS1 shell variable and see what you
prefer.