How can I have the return string of a program appear in my tcsh prompt?

1

I am using vcprompt to provide me with the git branch and dirtiness status. It returns it as a string.

How can I catch this string in my tcsh prompt setting? I guess I need to put the call to vcprompt somehow in the prompt definition, but I can't find the syntax for that.

Edit: Solution is:

alias precmd "echo -n `vcprompt`"

K.-Michael Aye

Posted 2012-10-16T01:20:58.933

Reputation: 113

Answers

1

In the original C shell, you could simply embed command substitution directly into the prompt variable, which I always thought made more sense. Under tcsh, you have to set up the precmd alias to do it. I'm not familiar with vcprompt but I assume it generates a newline at the end, so you'll probably want to use echo -n to throw away that newline, putting the prompt on the same line as the command, not the line before. Set prompt to whatever you want following; here I'm assuming you'll want a space.

alias precmd echo -n `vcprompt`
set prompt = ' '

Nicole Hamilton

Posted 2012-10-16T01:20:58.933

Reputation: 8 987

Almost. Had to put quotes around everything after precmd. (And there seems to be no frickin' way to write that command line in a comment here without some markup happening... :( – K.-Michael Aye – 2012-10-26T22:41:40.460