I am trying to set my csh prompt to the raw output of a particular command. I know how to do that for simple outputs; for example:
set prompt=`echo propmt%|sed "s/pm/mp/"`
... results in a prompt of:
prompt%
But the prompt I want is more complex. First, it has multiple lines. I know how to do that directly (i.e. not via the output of a command):
set prompt="This is a line\nThis is another\nAnd this is the last% "
... results in:
This is a line
This is another
And this is the last%
But if I try to do that same thing through a command:
set prompt=`echo "This is a line\
This is another\
And this is the last% "`
... the prompt becomes just:
This
... not even This is a line
; just This
.
On top of that, the specific command that I want to use will output not just multiple lines, but also a bunch of other characters that I assume csh
and/or set
will interpret in ways that I don't intend. Specifically:
cowsay -f ghostbusters "BOOOOOOOOOOOOOOOOOOOOOOOOO \
? \
? You are using CEEEEEE SHELLLLLLLLLLLLLLLLL\
? \
? Be my guest, but you have no one to blame but\
? YOURSELLLLLLLLLLLLLLLLLLLLLLF"; echo; echo "% "
... which outputs:
_________________________________________
/ BOOOOOOOOOOOOOOOOOOOOOOOOO \
| |
| You are using CEEEEEE |
| SHELLLLLLLLLLLLLLLLL |
| |
| Be my guest, but you have no one to |
\ blame but YOURSELLLLLLLLLLLLLLLLLLLLLLF /
-----------------------------------------
\
\
\ __---__
_- /--______
__--( / \ )XXXXXXXXXXX\v.
.-XXX( O O )XXXXXXXXXXXXXXX-
/XXX( U ) XXXXXXX\
/XXXXX( )--_ XXXXXXXXXXX\
/XXXXX/ ( O ) XXXXXX \XXXXX\
XXXXX/ / XXXXXX \__ \XXXXX
XXXXXX__/ XXXXXX \__---->
---___ XXX__/ XXXXXX \__ /
\- --__/ ___/\ XXXXXX / ___--/=
\-\ ___/ XXXXXX '--- XXXXXX
\-\/XXX\ XXXXXX /XXXXX
\XXXXXXXXX \ /XXXXX/
\XXXXXX > _/XXXXX/
\XXXXX--__/ __-- XXXX/
-XXXXXXXX--------------- XXXXXX-
\XXXXXXXXXXXXXXXXXXXXXXXXXX/
""VXXXXXXXXXXXXXXXXXXV""
%
That's what I want as my csh prompt. At this point, I feel obligated to note that I am not kidding.
I suppose I could forget about running a command to generate it, and instead just manually converting it to a single-line string that's properly escaped for set prompt
, but:
- That seems like a pain;
- I'd like to be able to quickly and easily change the prompt to similar but different things.
So, I'm hoping for some way to tell set prompt
"Just use the raw output of (arbitrary-command); don't interpret any of it as special characters or whatever". Is there a way? Or any alternate suggestions to accomplish what I want? Thanks.
CodePudding user response:
Maybe it's better to use the precmd
alias for this:
alias precmd 'cowsay -f ghostbusters << EOF \
line 1 \
\
line 2 \
\
line 3 \
EOF'
From csh(1):
precmd Runs just before each prompt is printed. For example, if one
does
> alias precmd date
then date(1) runs just before the shell prompts for each command.
There are no limits on what precmd can be set to do, but
discretion should be used.
Or you can make it a different file to avoid all the backslashes:
alias precmd 'source ~/cowsay'
# ~/cowsay
cowsay -f ghostbusters << EOF
line 1
line 2
line 3
EOF