
當刪除其後的文字或在歷史記錄中走得太遠時,我的 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\]'
)