Linux bash 行覆盖自身

标签 linux bash

<分区>

我制作了自己的 .bashrc(下面的部分代码)并通过按下向上/向下箭头进行测试:我发现 命令的历史覆盖行的静态文本或保留最后一个命令并在其上打印新的。如何解决?

function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

RESTORE=$(echo -en '\033[0m')
RKNAME=$(echo -en '\033[38;5;106m')
RKPATH=$(echo -en '\033[38;5;229m')
RKBRANCH=$(echo -en '\033[38;5;44m')
RKGIT=$(echo -en '\033[38;5;250m')

pathToFolder=$PWD;

if [[ $pathToFolder =~ .*_GitRepo.* ]]
then
    PS1='${RKNAME}\u@\h${RESTORE} ${RKGIT}Git ${RKPATH}\W\ ${RKBRANCH}$(parse_git_branch) \n ${RKGIT}-- $ ${RESTORE} '
    fi

最佳答案

解决我的问题是:

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.

谢谢@Gillies 提供链接 Why is this bash prompt acting strangely/disappearing, and how do I fix it (OS X)?

关于Linux bash 行覆盖自身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34790851/

相关文章:

c - netlink_kernel_create 函数出错

linux - tcl中如何改变目录文件的状态?

linux - 命令面板中缺少 "Shell Command: Install"命令 - VS 代码 - ubuntu

linux - 为什么我的 init.d start-stop-daemon 脚本不能在启动时启动应用程序,但我可以手动启动该服务?

r - 将参数从对 bash 脚本的调用传递到 Rscript

bash - 在 Bash 中,如何测试变量是否定义为 "-u"模式

linux - 无法在 bash 中分配变量。获取命令未找到错误

linux - 无法从 bash 运行 Expect 脚本

linux - 如何在linux中递归计算某些文件的总大小

mysql - Bash 脚本 : Mysql query field to variable