我的目标是通过eval在csh shell中设置一个提示符。
我创建了一个tcl脚本来打印命令(在现实生活中它做的更多):
puts "set prompt="%m %{\033[1;31m%}red prompt%{\033[0m%} %~ >""
然后,在csh中,我定义了一个别名:
alias red_prompt 'eval `/usr/bin/tclsh test_prompt.tcl`'
当我使用别名时,我得到一个错误:
> red_prompt
Missing ].
我试着玩反斜杠,但它没有帮助。
我怎样才能使它工作?
你真的不需要一个外部命令;您可以使用%{...%}
输出转义序列:
set prompt = '%{ 33[1;31m%}RED%{ 33[0m%}%% '
相关手册条目:
%{string%}
Includes string as a literal escape sequence. It should be
used only to change terminal attributes and should not move
the cursor location. This cannot be the last sequence in
prompt.
也有一些快捷键用于突出,粗体和下划线(但不包括颜色):
%S (%s)
Start (stop) standout mode.
%B (%b)
Start (stop) boldfacing mode.
%U (%u)
Start (stop) underline mode.