Welcome!

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

SignUp Now!

Custom prompt - pretty easy to modify.

Sep
32
1
It might be too noisy for some, but here's some custom prompt code that helps show OS/Host/Git Context/Error level/Subshell Depth.

Preview with commands to display the status bits
PromptCapture.JPG



In tcstart.btm
library /r %ROOT\library prompt %%@execstr[BuildPrompt %%?]

Library Code:
BuildPrompt { @echo off setlocal set LASTEXITCODE=%1 set CYAN=$e[36;1;44m set WHITE=$e[m$e[97;44m set GREEN=$e[32;1;44m set RED=$e[1;91;44m set YELLOW=$e[1;93;44m set HOST=%[HOSTNAME] rem in case no default already set iff %HOST == "" then set HOST=%@lower[%_winname] endiff iff %_elevated then rem Mark in red since we a sudo/root set HOST=%[RED]%[HOST] endiff set EXITSTATUS= iff %[LASTEXITCODE] then rem Show the return status in red if last command failed set EXITSTATUS= %[RED](%[LASTEXITCODE]) endiff set SUBSHELL= iff %[_SHELL] then rem If not the main shell, show shell depth in yellow set SUBSHELL= %[YELLOW](%%[_SHELL]) endiff rem Uh...There's got to be a better way. Show relevent git repo in green set GITREPO=`[%@name[%@execstr[git config --get remote.origin.url 2>nul:]]` set GITBRANCH=`%@execstr[git branch --show-current 2>nul:]]` set GITINFO=%[GREEN]%[GITREPO]/%[GITBRANCH] rem UNAME is set to 'Windows', Because with WSL 'hostname' isn't quite enough anymore set OSHOST=%[CYAN][%OS/%HOST] rem current date and time set DATETIME=%[WHITE]$d, $T echo %[OSHOST] %[DATETIME]%[SUBSHELL]%[EXITSTATUS]$_%[GITINFO] %[WHITE]$~\ endlocal }
 
I did something like this, but after decades, it became super unwieldy when I wanted to put %@FUNCTIONS in it that ran every time prompt was viewed.

I ended up using my stuff that is very much like your stuff, but echoing %PROMPT>prompt.cmd (which is a nice habit anyway, so if you are ever in CMD, you still have the prompt you generated ready to go!, I do this with my SetPath.bat that builds my path too, it generates a setpath.cmd) ....
.... and then hand editing it and slapping it at the end of my prompt-claire.bat in frustration. Lol.

I did eventually get what I want. Don't make me put the PATH in cursive. I'll do it.

1731616795719.webp


(2 minutes later)
oh nooooo, i did it
1731617001139.webp


Anyway, if you can figure out how to BUILD a prompt and get it working with more than 1 [i could achieve 1, but not 2] realtime var/func working. PLEEEEEEEEEEEEEEEEEEASE let me know. I come back to it in frustration every few years. I can get %_CPUUsage working but not %@functions or even two different vars. And TCC doesn't render prompt "$" values inside its functions so i had to come up with time my own way, put de-military-time stuff with %@IFs into it and it's a horrible beautiful mess.

But it's hard-coded and not generated like your (or my) preferred method, and it makes me feel.... less in control
 
Back
Top