PROMPT with git branch

Jul 22, 2015
2
0
#1
I'm looking to duplicate some of the functionality that my other programmer friends utilize in TCC.

Specifically, the ability to output the current git-branch of the directory that I'm in.

Not every directory will be a git directory, and I would want any directory under the local repo to report the branch.

Anyone accomplished this?
 

samintz

Scott Mintz
May 20, 2008
1,295
11
Solon, OH, USA
#2
I am not familiar with git. How do you get the information you are interested in? I assume there is a git command that returns that information.

Assuming you have a function that returns the text you want, lets call it @gitbranch, you could create a PROMPT that looks like this:
Code:
PROMPT [%@if[%@gitbranch[].==.,,(%@gitbranch[]) ]$P]$s
You could also do something similar with TITLEPROMPT to update the Tab text or console window title.

Assuming the command to get the branch is "git branch --list" then a simple @gitbranch could be:
Code:
function gitbranch=`%@execstr[git branch --list]`
If the command returns data that needs to be parsed, then you can use @WORD and/or have @execstr return a specific line of the output.