Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

TCC and Git

samintz

Scott Mintz
May
1,582
27
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
 
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.
 
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.
 
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:\]
$
 
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.
 

Similar threads

Back
Top