Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

closed as not a real question by terdon, Breakthrough, mpy, Olli, Scott Jun 11 '13 at 0:47

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 1 down vote accepted

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"

share|improve this answer
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.