2

How to reduce the command line prefix length (i.e folder name or path in bash)?

For example:

venu@venupc:~$ cd Documents/Code/new/
venu@venupc:~/Documents/Code/new$

I want to display present folder name new instead of complete path (venu@venupc: new$).

Braiam
  • 67,791
  • 32
  • 179
  • 269
Venu Gatla
  • 31
  • 1
  • 2
  • 5
  • 2
    http://superuser.com/questions/60555/show-only-current-directory-name-not-full-path-on-bash-prompt – Rinzwind Jan 23 '14 at 11:20
  • None of the AU answers there point to the real solution, as the SU question does: use \W. So I vote to reopen the question. – enzotib Jan 23 '14 at 12:00

1 Answers1

0

Read man bash, the PROMPTING section, and about the PROMPT_DIRTRIM environment variable.

  PROMPT_DIRTRIM
          If set to a number greater than zero, the value is used as the number of trail‐
          ing  directory  components to retain when expanding the \w and \W prompt string
          escapes (see PROMPTING below).  Characters removed are replaced with an  ellip‐
          sis.

Add export PROMPT_DIRTRIM=1 to ~/.bashrc, and you'll get close to what you want.

waltinator
  • 36,399
  • Even after 'adding export PROMPT_TRIMDIR=1' to ~/.bashrc not solved the problem. I have added below line in the ~/.bashrc to solve the issue. export PS1='[\u@\h \W]$ ' – Venu Gatla Feb 12 '14 at 03:57
  • My mistake. The variable is really called PROMPT_DIRTRIM walt@squid:~/gsettings(0)$ cd /usr/bin/X11/X11/X11/X11 +walt@squid:/usr/bin/X11/X11/X11/X11(0)$ export PROMPT_DIRTRIM=1 +walt@squid:.../X11(0)$ walt@squid:.../X11(0)$ echo "$PS1" | cat -A ${debian_chroot:+($debian_chroot)}${SUBSHELL}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[1;31m\]($?)\[\033[00m\]\$ $ +walt@squid:.../X11(0)$ – waltinator Feb 15 '14 at 02:01