在提示符下将输入的命令加粗
这是我当前的 PS1 提示符定义,来自 .bashrc:
PS1='\[\033[01;33m\]★ \[\033[01;30m\]\w \[\033[32m\]\$ \[\033[m\]'
我的命令提示符工作得很好,我喜欢它,但我想再添加一件小事。我真的希望能够将我输入的文本(提示符下的命令)粗体显示。
我知道我可以将最后一个转义代码更改为:
\[\033[01m\]
这将使我输入的命令提示文本变为粗体,但它也会对输入命令的输出执行有趣的(不需要的)操作。
有办法做到这一点吗?如果是这样,怎么办?
我在 Ubuntu 中运行 gnome-terminal。
This is my current PS1 prompt definition from by .bashrc:
PS1='\[\033[01;33m\]★ \[\033[01;30m\]\w \[\033[32m\]\$ \[\033[m\]'
My command prompt works great and I love it, but I would like to add one more little thing. I would really like to be able to have the text I enter (commands at the prompt) bold.
I know I could change the last escape code to be:
\[\033[01m\]
Which would make the command prompt text I enter bold, but it also does funny (undesirable) things with the output of entered commands.
Is there a way to do this? If so, how?
I am running gnome-terminal in Ubuntu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也想这么做。我在这里找到了答案: https://wiki.archlinux.org/index.php/Color_Bash_Prompt #Different_colors_for_text_entry_and_console_output
将此行添加到 ~/.bashrc 中,这将在显示命令输出之前重置您在 PS1 变量中设置的颜色:
trap 'echo -ne "\e[0m"' DEBUG
I was looking to do this too. I found an answer here: https://wiki.archlinux.org/index.php/Color_Bash_Prompt#Different_colors_for_text_entry_and_console_output
Add this line to your ~/.bashrc which will reset the color that you set in your PS1 variable before displaying your command's output:
trap 'echo -ne "\e[0m"' DEBUG