So I know this question have been asked a lot, but I don’t find any suitable answers. I’m looking to display the name of the current git rev in my prompt, but in a pretty way : if I’m on a branch, I want the name of the branch; if it’s not a branch, I’d like the relative name (ie master~2) in my prompt.
At first, I was using something like what you can see here. It worked well : I had the name of the branch, or the rev SHA1 number. Then I moved to an approached based on git name-rev, which was great at first, but then I noticed that the name was mixed up sometimes : after merging master into staging, on both branches I had master in my prompt. Given how much I rely on this, I can’t have this. But having master~2 instead of a SHA1 number was really great.
So I hope there’s a way to combine both approaches. If it’s possible to display the tag name too, I’ll take it (though I don’t use them much – yet). And the top would be to have git only commands, no looking up git internal files — they could change at some point.
Thanks for reading!
Taken from zsh-git repository: https://github.com/jcorbin/zsh-git/blob/master/functions/zgitinit#L70
You may also consider using zsh 🙂