TCC and Git

samintz

Scott Mintz
May 20, 2008
1,294
11
Solon, OH, USA
#1
Robin Siebler posted earlier about getting the git branch into the prompt, but that thread appears to have been deleted. This is what I do:
Code:
FUNCTION gitbranch=`%@execstr[set _gb=%@execstr[git rev-parse --abbrev-ref HEAD 2>nul] & if %[_gb]. != . echo. %_gb (%@execstr[git describe --always]) & unset _gb]`
PROMPT=$e[37;%@if[%@remote[%_disk] eq 0,42,41];1m[$P]$e[22;40;36m%@gitbranch[]$e[22;40;33;1m$_$$$s
That prints the PWD inside brackets, followed by the current branch, followed by the tag this branch is based on. The prompt is colorized to be White on Green for local drives and White on Red for network drives.
1539185690409.png
 
Oct 10, 2018
9
0
#2
Thanks! That mostly does what I am trying to do. However, if I am not in a folder that is a git repository, it does not remove the git information from the prompt.
 

samintz

Scott Mintz
May 20, 2008
1,294
11
Solon, OH, USA
#3
Yes it does. If you're in an untracked subdirectory it won't. If your repo is located at C:\Foo. Then anything in Foo's tree will be assumed to be part of the repo. But C:\Bar won't show anything because it's not a git repo.
 

samintz

Scott Mintz
May 20, 2008
1,294
11
Solon, OH, USA
#5
What do your PROMPT and @gitbranch function look like. It sounds like you either left off the backticks when creating the function and/or entered a single % when creating your prompt. So it got created as a fixed value.
Code:
[R:\]
$ function
gitbranch=%@execstr[set _gb=%@execstr[git rev-parse --abbrev-ref HEAD 2>nul] & if %[_gb]. != . echo. %_gb (%@execstr[git describe --always]) & unset _gb]

[R:\]
$ set prompt
PROMPT=$e[37;%@if[%@remote[%_disk] eq 0,42,41];1m[$P]$e[22;40;36m%@gitbranch[]$e[22;40;33;1m$_$$$s

[R:\]
$
 

samintz

Scott Mintz
May 20, 2008
1,294
11
Solon, OH, USA
#6
I have this in my TCSTART.btm file:
Code:
function gitbranch=`%@execstr[set _gb=%@execstr[git rev-parse --abbrev-ref HEAD 2>nul] & if %[_gb]. != . echo. %_gb (%@execstr[git describe]) & unset _gb]`
title %_4ver.%_BUILD
PROMPT=`$e[37;%@if[%@remote[%_disk] eq 0,42,41];1m[$P]$e[22;40;36m%@gitbranch[]$e[22;40;33;1m$_$$$s`
I have backticks on both the function and prompt definitions.