重击提示包装问题 [英] Bash Prompt Wrapping Issue

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

问题描述

我的自定义Bash提示似乎遇到了一种情况,与此处的情况非常相似:

I seem to be running into a situation with my custom Bash Prompt, very similar to this one here:

Bash提示行换行问题

我在想转义可能是我的问题(如上面的url中所述),我曾尝试过四处移动并删除方括号,但所做的只是弄乱了我的bash提示.有人可以帮忙吗?

I'm thinking escaping might be my issue (as mentioned in the url above) I've tried moving things around and removing my brackets, but all that does is mess up my bash prompt. Is someone able to lend a hand with this:

"What! \[\e[1;33m\]\w\[\e[m\]\[\e[37m\]\$(parse_git_branch)\[\033[00m\] \e[m\]$ "

推荐答案

必须将所有非打印段都用 \ [... \] 包围,并且所有打印段都必须不会被那些人包围.

All non-printing segments in the must be surrounded by \[...\] and all printing segments must not be surrounded by those.

在靠近结尾的 \ [... \] 中至少有一个空格.

You have at least one space inside \[...\] near the end.

您还拥有大量未封闭的 \ [(计算您的匹配对).

You also have a large number of unclosed \[ (count your matched pairs).

使用颜色代码本身的变量(如在链接的问题中)将简化在提示本身中查找转义符的位置.(尽管链接的问题将提示转义符也放入变量中,这使我难以理解到底发生了什么.)

Using variables for the color codes themselves (as in the linked question) will simplify seeing where the escapes need to go in the prompt itself. (Though the linked question puts the prompt escapes in the variables also which complicates seeing what's going on a bit to my mind.)

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

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