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


Scott Mintz
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:
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.
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.
$ function
gitbranch=%@execstr[set _gb=%@execstr[git rev-parse --abbrev-ref HEAD 2>nul] & if %[_gb]. != . echo. %_gb (%@execstr[git describe --always]) & unset _gb]

$ 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

I have this in my TCSTART.btm file:
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