重击提示历史问题 [英] Bash prompt history issue

查看:59
本文介绍了重击提示历史问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个很奇怪的问题,我无法在Google上找到一个好的答案(当然,总有可能我只是失败了)。在我的bash提示上,如果我给提示的一部分上色,则当我按向上键转到上一条命令时,经过一定数量的字符(特别是31个字符)后,我将无法转到行的开头。

This is a weird one that I haven't been able to find a good answer with Google (of course there's always the possibility that I just fail at that). On my bash prompt, if I color a part of the prompt, when I hit 'up' to go to a previous command, I can't go to the start of the line after it's past a certain amount of characters (specifically 31).

我当前的bash提示是:(颜色在我的.bashrc前面定义了)

My current bash prompt is this: (colors are defined earlier in my .bashrc)

PS1="[\u@$cyan\h$NC \w] "

但是如果我将其更改为:

But if I change it to this:

PS1="[\u@\h \w] "

它不再阻止我进入行首。

It no longer prevents me from going to the beginning of the line.

奇怪的是,从视觉上看,当我打到首页以开始到行的开头(或使用箭头键)时,它会在字符串中停止11个字符,但是如果我从那里编辑它,它确实从行的开头开始编辑。

The odd part, is visually, when I hit home to go to the beginning of the line (or use the arrow keys) it stops 11 characters in to the string, but if I edit it from there, it does edit starting at the beginning of the line.

有人知道为什么会这样吗?我想在进行服务器管理时在提示中使用颜色,这些颜色使我一眼便能区分盒子。

Does anyone know why this might be happening? I would like to use colors in my prompt as I do server administration and the colors is how I differentiate my boxes at a glance.

推荐答案

非打印序列(例如颜色代码)必须用 \ [ \] 包围,因此它们的长度不会被视为提示长度的一部分。

Non-printing sequences such as color codes must be surrounded by \[ and \] so their lengths are not counted as part of the length of the prompt.

这篇关于重击提示历史问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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