当删除其后的文本或在历史记录中走得太远时,我的 Bash 提示会自动清除。
登录时,提示看起来很正常。彩色用户名周围有白色括号,然后是白色 > 作为我的提示,但是,如果我在历史记录中向上移动两次,历史记录命令会覆盖我的提示:
[stonewareslord] > #Initial prompt. stonewareslord is green
| Cursor is above this pipe symbol
[stonewareslord] > ls #Up arrow pressed once. ls was my last command. Colors are normal, ls is white
| Cursor is above this pipe symbol
pwdonewareslord] > ls #Up arrow a second time. pwd overwrite [st. pwd is white and the other colors are normal.
| Cursor is above this pipe symbol
当我删除命令时也会发生这种情况:
[stonewareslord] > ls #Typed command after initial prompt. stonewareslord is green
| Cursor is above this pipe symbol
[stonewareslord] > l #Deleted one character
| Cursor is above this pipe symbol
#Deleted second character (line is blank). Anything I type is white
| Cursor is above this pipe symbol
bashrc 中可能影响此情况的行是:
color='\e[0;32m' #Green
reset='\e[0m' #Color is set back to normal (white)
prompt(){
printf "[$color%s$reset]>" `whoami`
}
PS1=""
PROMPT_COMMAND=prompt
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="%Y-%m-%d_%H:%M:%S "
export HISTFILE=~/.bash_eternal_history
readonly HOME
readonly HISTIGNORE
答案1
好吧,我想出了一个解决方法:
PROMPT_COMMAND=prompt
更改为:
PROMPT_COMMAND='PS1=`prompt`'
编辑:并且颜色被包裹在\[ \]
(即color='\[\e[0;32m\]'
)中