I know they have been asking a lot of this question and I got it worked perfectly, but one thing I don't understand is why this is different.

 #This will show the full path (/usr/bin)
 PROMPT_COMMAND='echo -ne "\033]0;${PWD}\007"'

 #This will set to the directory name only (bin)
 PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"'

The problem I have here is that I want to use the second one, but when I open a new tap it will go back to the default working directory, whereas the first one will keep the same working directory if I open another tap which I want that.


Strange. Maybe it has to do with when the pattern-expansion takes place in bash's order of processing.

Something like `PROMPT_COMMAND='BASED=${PWD##*/} echo -ne "\033]0;$BASED\007"' might do the trick.

EDIT: That didn't work? Maybe this will

set_prompt () {
    echo -ne "\033]0;$BASE_PATH\007"

  • It doesn't work at all :(
    – Ali
    Jun 8 '13 at 17:49
  • No? I'm pretty sure the issue is when bash expands the pattern. (what /else/ could be different in your examples?) So play with different things. But then, I could be wrong, also.
    – jpaugh
    Jun 8 '13 at 17:52
  • it works this way, but strange when opening a new tab then it will go back to the default working directory :(
    – Ali
    Jun 8 '13 at 17:57
  • Wait, the original tab changes its title when you open a new tab?
    – jpaugh
    Jun 8 '13 at 18:00
  • yes it does change, but when I open a new tab it will go back to the default one when I open terminal
    – Ali
    Jun 8 '13 at 18:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.