1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Call a complex function

Discussion in 'Support' started by nickles, Apr 4, 2016.

  1. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    How would I call a complex function (involving the call and evaluation of several exernal programs) to set PROMPT dynamically?
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,970
    Likes Received:
    30
    Perhaps @EXECSTR[].
     
  3. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    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.
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,311
    Likes Received:
    39
    So why wouldn't @EXECSTR work for that?
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,970
    Likes Received:
    30
    ($PROMPT_COMMAND) ... that would seem about the same as
    Code:
    set prompt=%%@execstr[complicated.BTM]
     
  6. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,970
    Likes Received:
    30
    Actually, I think it should have this form:
    Code:
    set prompt=`%@execstr[complicated.btm]`
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,970
    Likes Received:
    30
    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.
     
  8. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    @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.
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,970
    Likes Received:
    30
    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> 
     
  10. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,311
    Likes Received:
    39
    Nice! I'd forgotten that $ was one of the supported characters in variable names....
     
  11. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    0
    @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!
     
  12. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,970
    Likes Received:
    30
    If it's down to a one-liner, do it in TCSTART.BTM. (?)
     
  13. dcantor

    Joined:
    May 29, 2008
    Messages:
    507
    Likes Received:
    3
    This seems to work for me:
    Code:
    if isalias post_exec post_exec
    as the last command of TCSTART.BAT (or .BTM).
     
  14. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,970
    Likes Received:
    30
    Nice one!
     

Share This Page