When I move around to different directories in terminal, I end up with really long prompts with the full directory path of my current working directory. This is a lot of extra clutter when I really just want an active terminal in that directory and can remember where I am. How do I modify what is shown in the prompt? I'm going to find out!
Current:
xxxxx@xxxxx:/xxxxx/xxxxxxxxx/xxxx/xxxxxxxx/xxxxxxxx$
What I'd like is probably just the name of the current directory without the full path.
It turns out that the prompt is very easy to modify! You just edit your .bashrc to add a line:
cd
gedit .bashrc (I'm not on board with emacs yet)
Here are some cool options I found on various forums:
This one removes all directory information and makes the prompt be an arrow:
export PS1="-->"
This one prints the full path, but then gives you a new line with a simple > for the prompt:
export PS1="\w\n>"
This does exactly what I want! I'm so used to the $ as a prompt that I want to keep it, but this gives me just the current directory without the full path! I also learned that the part of the path I am interested in is called the "basename of the current working directory."
export PS1="\W$"
New prompt:
xxxxxxxxx$
I might decide that I want the xxxxxx@xxxxx part back in the prompt, but for now, I'll keep the prompt short.
source:
http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html
I use a variation on Debian/Ubuntu's default colorized prompt: (simplified somewhat for clarity)
ReplyDelete# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
linux) color_prompt=yes;;
xterm*) color_prompt=yes;;
esac
if [ "$color_prompt" = yes ]; then
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='\u@\h:\w\$ '
fi
unset color_prompt
That'll enable color prompts in specific terminals, using green for user@host and blue for directory. Most graphical terminals report themselves as xterm. If you never wind up using serial teriminals there probably isn't any need for that logic. Obviously you can replace \w with \W in both lines to get your shorter prompts. The rest of the garbage is ANSI terminal escape sequences: http://en.wikipedia.org/wiki/ANSI_escape_code
To make user@host red for root to help keep things root obvious just change the colorized PS1 to:
PS1='\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
The 01;32m (bold; blue) changed to 01;31m (bold, red)