这是为什么bash提示符举止怪异/消失,以及如何修复它(OS X)? [英] Why is this bash prompt acting strangely/disappearing, and how do I fix it (OS X)?

查看:153
本文介绍了这是为什么bash提示符举止怪异/消失,以及如何修复它(OS X)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我承认我使用一个有点啰嗦的bash提示:

I admit that I use a somewhat long-winded bash prompt:

--(username)-(Wed April 01|12:00:00)--(~ $

近日,笔者得到了光明的想法来改变它,以便根据从previous命令退出值,如果成功,则()的内部单元S是绿色,如果失败,他们会红色。我得到它的工作在大多数情况下(一些奇怪的退出状态会改变颜色别的东西,但我确定它),但是键入命令是多条线路的时候,并导致终端滚动时,提示消失!我提示正常工作时,有没有颜色,所以我猜它是与我的颜色转义,特别是我未闭合[的,但我不能针下来。

Recently, I got the bright idea to change it so that depending on the exit value from the previous command, if success, the interior elements of the ()'s would be green, and if failure, they would be red. I got it working for the most part (some odd exit statuses will change the color to something else, but I'm ok with it), but when typing a command which is more than one line, and causes the terminal to scroll, the prompt disappears! My prompt worked fine when there was no color, so I'm guessing it is related to my color escaping, and particularly my unclosed ['s, but I can't pin it down.

#.profile
export PS1='--(\e[$((32-${?}))m\u\e[0m)-(\e[$((32-${?}))m\d\e[0m|\e[$((32-${?}))m\T\e[0m)--(\e[$((32-${?}))m\w\e[0m \$ '

在此先感谢!

推荐答案

这听起来像这个应该解决您的问题。

It sounds like this should solve your problem.

这似乎为我 * 工作:

export PS1='--(\[\e[$((32-${?}))m\]\u\[\e[0m\])-(\[\e[$((32-${?}))m\]\d\[\e[0m\]|\[\e[$((32-${?}))m\]\T\[\e[0m\])--(\[\e[$((32-${?}))m\]\w\[\e[0m\] \$ '

* 很好,真的出口PS1 ='\\ü@ \\ H:\\ W \\ $'工程我

要引用链接后,答案就在于加入 \\ [和\\] 在你的周围PS1声明中所有的颜色序列:

To quote the linked post, the answer lies in adding \[ and \] around all of your color sequences in your PS1 declaration:

在我有以下值PS1:

\\ E [0;34米\\ H:!\\ W [] \\ $ \\ E [0米

'\e[0;34m\h:\w [!]\$\e[0m '

这给了我以下形式的一个不错的蓝色提示

which gave me a nice blue prompt of the following form

主机名:工作目录[命令号] $

hostname:working-directory [command-number]$

不过,我拥有了你做了同样的换行问题。伦敦定盘插入\\ [和\\]周围的ANSI转义,这样shell知道不包括他们在换行计算。这导致下面的值用于PS1:

However, I had the same line-wrapping problem you did. The fix was to insert \[ and \] around the ANSI escapes so that the shell knows not to include them in the line wrapping calculation. This results in the following value for PS1:

\\ [\\ E [0;34米\\] \\ H:!\\ W [] \\ $ \\ [\\ E [M \\]

'\[\e[0;34m\]\h:\w [!]\$\[\e[m\] '

这篇关于这是为什么bash提示符举止怪异/消失,以及如何修复它(OS X)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆