Reputation: 508
I have several terminals open in one window, with the title showing the fullpath of the current directory. The problem I'm having is: the paths are so long it's hard to distinguish between them.
What I would like to display is the current directory name (not the full path) in the title.
Here is my current title in my .bashrc
PROMPT_COMMAND='echo -ne "\033]0;$$ ${BRANCH} ${PWD/#$HOME} \007"'
I thought just replacing the $PWD with $CWD would work, but bash doesn't have it built in. This solution below only works the first time.
https://stackoverflow.com/a/22235278/345097
After changing directories again the title never gets updated.
export DIR=`echo $PWD | rev | cut -f1 -d'/' | rev`
export DIR2=`basename ${PWD}`
PROMPT_COMMAND='echo -ne "\033]0;$$ ${BRANCH} ${DIR} \007"'
Here's my PS1 as a reference:
PS1="[\033[00;31m]\h [\033[00;32m] \w [\033[00;36m] > [\033[00m]"
Example:
cd /share/project/master/app/src/com/project/dao
Currently the Title displays
5670 master /share/project/master/app/src/com/project/dao
Desire Title
5670 master dao
Upvotes: 2
Views: 5797
Reputation: 532093
Since $PWD
is guaranteed to be a directory, you might use either of the following:
PROMPT_COMMAND='echo -ne "\033]0;$$ ${BRANCH} $(basename "$PWD") \007"'
PROMPT_COMMAND='echo -ne "\033]0;$$ ${BRANCH} ${PWD##*/} \007"'
Upvotes: 5