Welcome!

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

SignUp Now!

Call a complex function

Jun
223
0
How would I call a complex function (involving the call and evaluation of several exernal programs) to set PROMPT dynamically?
 
Nope. The function I'd like to use is too complex for a standard function (it's a Git prompt - like I use it in bash). I'm looking for method to produce a new string before the prompt returns, and PROMPT just spitting out that string. Linux btw. does it by providing a callback hook ($PROMPT_COMMAND). But in TCC I haven't seen anything the like.
 
($PROMPT_COMMAND) ... that would seem about the same as
Code:
set prompt=%%@execstr[complicated.BTM]
 
Actually, I think it should have this form:
Code:
set prompt=`%@execstr[complicated.btm]`
 
You might also try the special alias POST_EXEC. Being an alias, it can have several commands (separated by "&"), or it can execute complicated.btm. In any event, if POST_EXEC creates my_prompt_string and then (lastly) does "SET PROMPT=my_prompt_string", it should work.
 
@charles
Wasn't aware that %@execstr[] could call BTM files. However this seems to be slower than using the alias approach (@Rex: could you comment on this?). Also, this approach suffers from the below problem too.

@vince
Unfortunately setting PROMPT in tcstart.btm seems to be treated differently. Setting PROMPT from the command line (e.g. set prompt=%_PID%$s%%git_prompt%%$g$s) works (set PROMPT gives me: <some_pid>$s%git_prompt%$g$s); setting PROMPT in tcstart.btm (same assignment) doesn't work (set PROMPT gives me: <some_pid>$s$g$s), the variable gets eliminated.
I also tried `%...%`, ^%...^%,`%%...%%`, and ^%^%...^%^%, to no avail.
 
This should work in both places:
Code:
SET PROMPT=%[_PID]$s%%[git_prompt]$g$s
The value of git_prompt will be an empty string if it isn't defined. If it becomes defined, a non-empty string will appear.
Code:
2244 > type %_tcstart | grep git
SET PROMPT=%[_PID]$s%%[git_prompt]$g$s

2244 > set prompt
2244$s%[git_prompt]$g$s

2244 > set git_prompt=foo

2244 foo>
 
This should work in both places:
Code:
SET PROMPT=%[_PID]$s%%[git_prompt]$g$s
The value of git_prompt will be an empty string if it isn't defined. If it becomes defined, a non-empty string will appear.
Nice! I'd forgotten that $ was one of the supported characters in variable names....
 
@vince
Seems my understandig of %s to reference variables was too CMD-bound. %[...] obviously behaves like ${...} in the bash; wasn't aware of that...

One ugliness remains though: when starting a new TCC session, POST_EXEC is not executed prior to the first prompt. Of course one might argue "No command was executed before this first prompt", and would be correct. It would be nice however, to have the desired information right in the first prompt i.e. w/o having to resort to call the POST_EXEC alias manually once.

@all
Thanks for your help!
 
This seems to work for me:
Code:
if isalias post_exec post_exec
as the last command of TCSTART.BAT (or .BTM).
 

Similar threads

Back
Top