Home > Software engineering >  How to show/hide current working directory in bash prompt?
How to show/hide current working directory in bash prompt?

Time:05-04

When I use Linux console it shows way to current directory "admin@servername:/home$" or not - just "$". How to turn on/ off this hint (way to directory)? Probably it should be changes in file .bashrc in PS1 = '\u@\h:\w$', but this value in PS1 allready. Here is code sample from .bashrc:

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

What exactly should be done to show/ hide way to current directory? Thankyou in advance.

CodePudding user response:

You should look up Bash prompt special characters.

As you can see in the list, the current working directory is \w, and \a is the bell character, so just remove those.

  • Related