首页 > 解决方案 > 通过 eval 提示 csh 颜色

问题描述

我的目标是通过 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 ].

我尝试使用反斜杠,但没有帮助。

我怎样才能让它工作?

标签: evalaliascommand-promptcsh

解决方案


您实际上并不需要外部命令;您可以使用%{...%}输出转义序列:

set prompt = '%{\033[1;31m%}RED%{\033[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.

推荐阅读