eval - 通过 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 ].
我尝试使用反斜杠,但没有帮助。
我怎样才能让它工作?
解决方案
您实际上并不需要外部命令;您可以使用%{...%}
输出转义序列:
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.
推荐阅读
- python - 如何找出时间是否在字典中链接?
- javascript - 从 getCookie() 函数获取并获取单个值
- excel - 使用列值作为条件发送电子邮件
- python - 如何在车辆路径问题中添加时间窗口?
- python - 找不到 Tmp 脚本文件 - Airflow - FileNotFoundError: [Errno 2] 没有这样的文件或目录
- sql - 用于从不同表中获取信息的 SQL 查询
- gitlab-ci - 使用 Gitlab CI 在 Cypress.io 上的一个条目中对并行运行进行分组
- reactjs - 如何获取 URL 并同时为 React 路由传递变量
- perl - 当 SSH 发生以下错误时 - 无法建立主 SSH 连接:主进程意外退出
- laravel - 通过cPanel部署Laravel 8 Application的正确方法