76
31
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
Great answer. Make sure you reboot in order this to take effect. Thanks! – Combine – 2018-05-31T09:00:57.723
Hm... I'm afraid it's already \w, but it seems like that
case
statement overrides it when i'm on an xterm, and the problem seems to be with thePWD
in thePROMPT_COMMAND
line. Do you know what I should put there? – Helder S Ribeiro – 2009-10-25T22:48:55.7504
\w
(lower case) sets it to full path,\W
(uppercase) trims to the final bit. the PROMPT_COMMAND is setting the window title in an xterm. check your TERM variable; if it doesn't start with "xterm" or "rxvt" then PROMPT_COMMAND isn't even getting run. – quack quixote – 2009-10-25T22:59:13.297Oh, yeah, duh. Sorry, I mixed upper and lowercase. That worked. Thanks! :) – Helder S Ribeiro – 2009-10-25T23:39:24.323