Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to do something like this in Bash:

how to format the path in a zsh prompt?

But everything I try results in the PWD being fixed to the first directory I start my terminal in. Strangely I've also got a function in my PS1 to put the current git branch in the prompt and that always updates so I'm confused as to why the PWD gets stuck. My current prompt is here incidentally.

I tried replacing \w with $(pwd|grep --color=always /) but that just gets stuck. I also tried doing it using a bash string replacement but that doesn't work either. ${PWD////$bldred/$bldblu} ($bldred and $bldblu are defined in my prompt.sh).

share|improve this question

2 Answers 2

The last part of the script:

case "$TERM" in
xterm*|rxvt*)
    PS1=...
...

is useless when you've set $PROMPT_COMMAND - that version of $PS1 will only run once. So you won't ever see a title update after the first run of that script. You need to add the title change in $PROMPT_COMMAND with everything else.

Move that switch inside the true branch of

if [ "$color_prompt" = yes ]; then

and build to different $PROMPT_COMMANDS based on that. Works for me.

share|improve this answer
    
That part actually came from Ubuntu default file, wasn't aware that could be affecting it. Actually I ended up realizing that he had put the whole thing in PROMPT_COMMAND including the PS1 part and it worked. –  Ibrahim Nov 23 '12 at 7:45

When including a dynamic variable in your prompt you need to quote it.

I don't quite understand some of your PROMPT_COMMAND stuff, but try PS1='${PWD////'"$bldred/$bldblue"'} \$' by itself and see if it works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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