Skip to content
This repository has been archived by the owner on Dec 10, 2019. It is now read-only.

Prompt refuses to update when changing directories #14

Closed
Pewpewarrows opened this issue Jun 16, 2011 · 8 comments
Closed

Prompt refuses to update when changing directories #14

Pewpewarrows opened this issue Jun 16, 2011 · 8 comments

Comments

@Pewpewarrows
Copy link

As the title suggests, whenever I cd into a directory that has version control in it, my prompt never updates to reflect that. I've followed the Install instructions verbatim:

$ curl -sL https://github.com/xvzf/vcprompt/raw/master/bin/vcprompt > ~/bin/vcprompt
$ chmod 755 ~/bin/vcprompt
$ export PS1="$(vcprompt) $PS1"

I then cd into any project directory covered by svn, git, or hg (I've tried all three). Just running the command correctly tells me any information:

$ vcprompt
svn:trunk

However, my prompt still stays as $. If I wait to run the export PS1="$(vcprompt) $PS1" line until I'm in a project directory already, then the prompt is correctly updated to be svn:trunk $. However, that svn:trunk stays in the front frozen like that no matter what I cd into from that point on. So even moving to my home directory still shows svn:trunk $ as my prompt.

This occurs both on my OSX and Ubuntu workstations. Both are running Python version 2.6.x. Both are using bash as the shell. To prevent any conflicts, I've made sure that the only line in my .bash_profile or .bashrc has been adding ~/bin to my $PATH.

Do you have any idea what might be causing this?

@Pewpewarrows
Copy link
Author

Ended up stumbling upon a solution this morning. There's a bash variable called PROMPT_COMMAND, that if set, will execute every time a prompt appears (whether it's after a cd or any other command on the terminal).

By placing this in my .bash_profile or .bashrc, I was able to get vcprompt to always show the latest directory info:

update_prompt() {
    export PS1="$(vcprompt) blah blah blah"
}
PROMPT_COMMAND=update_prompt

Anything that I needed to update every time a new prompt appeared, I threw into that update_prompt function, such as looking for the $VIRTUAL_ENV variable being set, using a custom vcprompt format, etc.

I don't know if the PROMPT_COMMAND shenanigans is only a problem because of some system configuration of mine, or whether this is a universal issue that the docs just failed to mention. In which case, an updated README would be nice :)

@djl
Copy link
Owner

djl commented Jun 16, 2011

Weird. I noticed this happening myself while I was working on the README overhaul. Testing it again now, I can't get it to happen again.

I'm fairly certain it's my crappy install procedure. I'll poke around some more and update the README if I find anything.

@djl
Copy link
Owner

djl commented Jun 16, 2011

Updated the instructions in 81b13b6. The problem seemed to be the recursive use of $PS1.

Try that. It should be fixed now :)

@vbajpai
Copy link

vbajpai commented Jul 14, 2011

I had the same issue.

@xvzf: the updated instructions didn't help me.

@Pewpewarrows: the PROMPT_COMMAND trick worked for me

@djl
Copy link
Owner

djl commented Jul 14, 2011

That's what I get for not using bash :)

I'll update the instructions later.

@djl
Copy link
Owner

djl commented Jul 14, 2011

Oh! I found a simpler way to do it. Just escape the dollar sign:

export PS1="\$(vcprompt) blah blah blah"

@vbajpai, @Pewpewarrows: can you try this way and let me know if it works?

@vbajpai
Copy link

vbajpai commented Jul 14, 2011

On Jul 14, 2011, at 8:05 PM, xvzf wrote:

I have been doing that actually all this while.

@djl
Copy link
Owner

djl commented Jul 14, 2011

According to this page that should be working. Since it works for me in a bunch of different versions of bash, I'll settle on those instructions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants