The way my bash prompt is currently configured, it shows the whole path to the current directory. This is annoying when I'm deep inside a directory tree, as the prompt becomes so long that every command wraps into the next line. How do I make it show only the last part of the path?
This is what I have in my .bashrc
:
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
;;
*)
;;
esac
Best Answer
Change the
\w
(lowercase) to\W
(uppercase):Have a look at the Bash Prompt HOWTO for lots of fun details. example:
The
PROMPT_COMMAND
variable, if set, is a command that gets run before displaying the prompt specified inPS1
. In your case,PROMPT_COMMAND
runs anecho
statement with certain ANSI escape sequences that manipulate the titlebar of an Xterm.If you suspect your
PROMPT_COMMAND
is overriding yourPS1
prompt, you canunset
it and test things out:Finally, be sure that you're changing the
PS1
definition that actually gets used. Common locations are/etc/bash.bashrc
,/etc/profile
,~/.bashrc
,~/.bash_profile
,~/.profile
. The system files are generally (but not always) run before the user files.