In bash, I’m using a gitprompt to show the current status of my git repository, so my PS0 looks like this: [time][repo name][current path][number of added/modified files]$
This is set in ~/.bashrc where I’m exporting the PROMPT_COMMAND
export PROMPT_COMMAND=$PROMPT_COMMAND';export PS1=$(gitprompt.pl c=\+ u=\~ f=\* A=\^ B=\\\\ F=\ \>\> statuscount=1)'
I’m also using screen (which may come into play in this question). When I create a new screen window it automatically sources the .bashrc so my PS0 updates with the latest git status for that repo, unfortunately, that is the only time my PS0 updates with the git status.
How would I set this up so my git status updates every time I run a command in terminal or only on certain commands?
I would only need to run a git status when closing a file, moving, deleting or copying; so if I could set the prompt to run only on those commands, that would be best, but I would settle for it running on every bash command (without binding it to my return key).
Here is my entire prompt in ~/.bashrc
export PS0='\[\e[0;32m\][\t]\[\e[1m\][\h]\[\e[0;1m\][\w]\[\e[30;1m\]%{\[\e[1;32m\][%b]\[\e[0m\][%c%u%f%t]%}%{[%B%A%F]%}\[\e[0m\]\u\$ '
PS1=$(gitprompt.pl c=\+ u=\~ f=\* A=\^ B=\\\\ F=\ \>\> statuscount=1)
export PROMPT_COMMAND=$PROMPT_COMMAND';export $PS1'
It looks to me like the problem you’re encountering is that you’re already inside the single quotes, so it doesn’t want to parse the command a second time. It should be possible to get around that by putting the the PS1 assignment inside a bash function and then setting PROMPT_COMMAND:
It may also be possible to put your
gitprompt.plscript inside a function and return the results you need, so that it’s only printing a result if it’s inside a git repository.This could be achieved with something similar to the following:
(Note: This is untested, it may require a few tweaks)