Creating a custom prompt

Oct 10, 2018
9
0
I haven't used Take Command/TCC in years. Now, I'm struggling with a simple? task and the documentation. Here is what I would like to do:

I want to create a custom prompt that appends the git branch, if the current directory is in fact a git repository. I'm close, but I am flailing at the last step. Here is what I have so far:


Code:
function gitbranch=`%@word[1,%@execstr[git branch]]`


prompt %@if[direxist .git,$P$s(%@gitbranch[])$g,$P$g]

It sort of works, once, but I want it to be invoked every time I change directories. Also, I must be doing something wrong because if I run the prompt command outside of a git branch, the gitbranch function is still being executed. (It seems I should be using IFF instead of @IF, but I can't figure out how to get that to work either).

Also, is there an easy way to debug such things?
 
Last edited:

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
I know nothing about git, but DIREXIST .GIT will be true only if there is a subdirectory named .GIT (with the leading period) within the current directory. Which seems unlikely to me ...?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
prompt %@if[direxist .git,$P$s(%@gitbranch[])$g,$P$g][/CODE]

It sort of works, once, but I want it to be invoked every time I change directories.

I think you'll need to double the percent signs before @IF and @GITBRANCH. Or else put the whole thing in strong quotes. You want to store the functions in your prompt, so they'll be expanded when the prompt is displayed; not to expand them when you first define the prompt.

Also, I must be doing something wrong because if I run the prompt command outside of a git branch, the gitbranch function is still being executed.

That's right. Both values of the @IF are evaluated, whether the test works out to be true or false. (I'm pretty sure that that's nothing special to @IF; all functions have their parameters expanded before they get to see 'em.)
 
Oct 10, 2018
9
0
I think you'll need to double the percent signs before @IF and @GITBRANCH

That gets me one step further (Thanks!). But, if I am not in a git repo, "git branch" returns an error. Is there any way to suppress that?

Screenshot_2.png
 
Oct 10, 2018
9
0
I got it to work!

Code:
function git_branch=`%@word[1,%@execstr[git branch 2> nul]]`
prompt %%@if[direxist .git,$P$s(%%@git_branch[])$g,$P$g]
 
Oct 10, 2018
9
0
Ok! Now that I got that to work, I want to color it. But, I'm doing something wrong again, because I am getting a syntax error:

Code:
prompt %%@if[direxist .git, $e[94;40;1m $P$s $e[92;1m(%%@git_branch[]) $e[94;1m$g $e[37;40;1m,$P$g]

TCC: Syntax error "@git_branch["
) > ,C:\Users\robin_dev\Projects\github-demo>]

This is the prompt I want to have (with the git branch, if any, appearing between the parenthesis:
Code:
prompt $e[94;1m$p$s$e[92;1m( )$e[94;1m$g $e[37;40;1m
 
Last edited:
Oct 10, 2018
9
0
With help from Charles and Scott, I got what I wanted!

Code:
function gitbranch=`%@execstr[set _gb=%@execstr[git rev-parse --abbrev-ref HEAD 2>nul] & if %[_gb]. != . echo. (%_gb) & unset _gb]`
prompt=`$e[94;1m$p$e[92;1m%@gitbranch[]$e[94;1m$g $e[37;40;1m`
 
Similar threads
Thread starter Title Forum Replies Date
Joe Caverly Problem creating and switching to a DESKTOP Support 9
thorntonpg sync /S /F creating empty directories Support 5
C Language setup files, to use in creating similar for Multi-Edit Support 2
Jay Sage Creating or Editing TCMD Themes Support 6
Jay Sage Creating Files in Windows 7 Support 23
D Custom ini-file is not read, by tcmd.exe cli Support 6
C How to? Add date/time to custom tpipe based BTM Support 1
D How to? Using a custom ini file with TCC from Take Command Support 7
C custom string compare? Support 8
mfarah How to? So I want a custom directory for the plugins... Support 16
C How to? create a JPSoft BTM menu to run custom custom batch files Support 2
W Custom colors not saved in TCC 14 / Windows 7 x64 Support 4
tinjaw Looking for best practice for custom environment on tabs Support 0
vefatica ANSI, PROMPT ... ??? Support 1
FreezerBurnt ANSI Prompt messes up list output. Support 39
FreezerBurnt "Missing SETLOCAL" when initializing Visual Studio Command Prompt. Support 9
M How to? Black TCC Prompt Support 2
N Command execution slows down in TCC Prompt after a while Support 6
K Fixed Prompt display will be shifted after use dir to display a filename with Chinese. (v25.00.28 x64) Support 18
vefatica Timing commands with $= in the prompt? Support 16
samintz How to? Alias or prompt? Support 1
T Elapsed time format in prompt changed in TCC 25 Support 10
samintz MOVE and Prompt on overwrite Support 3
K TCC prompt background color Support 4
Alpengreis Problem if command prompt is not legacy Support 4
Joe Caverly Documentation Customizing the TCC Prompt Support 0
C How to? handle the UAC prompt on computer restarts with Everything Support 3
B when doing SFTP via IFTP to my secure site my users always get the finger print key prompt Support 1
M PROMPT with git branch Support 1
MikeBaas How to? SELECT: exclude files / display prompt Support 2
vefatica ? "prompt" command Support 3
S Elapsed time in TCC prompt question Support 0
Joe Caverly Determine if program started from command prompt Support 2
W Opening a new tab takes forever to get the command prompt Support 5
vefatica UAC prompt? Support 0
C How to? ctrl-c does not prompt "Terminate batch job" Support 2
Mordachai TCMD Prompt Here?!@ Support 14
vefatica Fixed DO, OSD, and cancel batch prompt Support 3
CWBillow Send Command-line with prompt? Support 6
David McClelland Why the prompt to del c:\* Support 7
S WAD BDEBUGGER command changes window title to "TCC Prompt" Support 4
S WAD Invoking BDEBUGGER changes window title to "TCC Prompt" Support 7
vefatica Cancel batch prompt? Support 0
1 CMD file kicks out to prompt Support 18
Steve Pitts Are you sure prompt from DEL command Support 5
Exolon Strange Prompt. Support 6
JohnQSmith TC 13 - Prompt Support 2
S TITLEPROMPT - width x height in prompt? Support 14
T Wrong prompt in Windows command console Support 3
S 4NT - delete from command prompt and recycle bin Support 12

Similar threads