4

From command line, long directory paths can take up the entire line:

long working directory path

Similar questions have been asked:

  1. Hides directory path in terminal
  2. Remove "PWD" from terminal
  3. Remove full path from terminal
  4. Show only current directory name on bash prompt

Steps taken:

  • Locate the .bashrc file in Debian /etc/bash.bashrc
  • From /etc directory in terminal: sudo gedit bash.bashrc
  • Find the line: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  • Change lowercase 'w' to an uppercase 'W' (in bold):

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\ W\$ '

  • Save (as sudo) and reload the .bashrc file solves the problem temporarily but not in new terminal window. The colors change, too (the green and blue gets knocked out and all text turns white)

1 Answer 1

5

You probably have your own PS1 definitions in ~/.bashrc (unless you are root) overriding the system-wide /etc/bash.bashrc (which is without colors). You should edit PS1 there.

In my ~/.bashrc the PS1 stuff looks like this (default Debian stretch):

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

The first definition is the one with colors. Change \w to \W in your ~/.bashrc and you should be good.

1
  • 1
    That's exactly what it was. Thanks for the direction.
    – Kelly
    May 28, 2019 at 22:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .