How to? Alias or prompt?

samintz

Scott Mintz
May 20, 2008
1,413
13
Solon, OH, USA
I have a custom prompt that displays the current Git branch for the directory I'm in.
Code:
gitbranch=%@execstr[set _gb=%@execstr[git rev-parse --abbrev-ref HEAD 2>nul] & if %[_gb]. != . echo. %_gb (%@execstr[git describe --always]) & unset _gb]
PROMPT=%@if[%@dirstack[] gt 0,[%@dirstack[]],]$e[37;%@if[%@remote[%_disk] eq 0,42,41];1m[$P]$e[22;40;36m%@gitbranch[]$e[22;40;33;1m$_$$$s
It works, but is slow in a repo with a lot of branches and history. So every time I issue a command in a git directory I have to wait a few seconds to get the prompt back. Is there a more efficient way to do this? When I run Git bash in a tab window, there are no delays with its prompt and it is displaying the same information.

Is there an alias that gets executed when a directory is changed?
Would this be faster if I created a POST_EXEC alias to do the same thing - i.e. set a gitbranch variable?