这是我自定义提示的脚本( .bashrc ):
my_prompt () {
if [[ $? -eq 0 ]]; then # set an error string for the prompt, if applicable
ERRPROMPT="✔"
else
ERRPROMPT="✘"
fi
if [[ "\$(type -t __git_ps1)" ]]; then # if we're in a Git repo, show current branch
BRANCH="\$(__git_ps1 '[ %s ] ')"
fi
if [[ -n "$SSH_CLIENT" ]]; then
REMOTE="${SSH_CLIENT%% *} "
fi
if [[ $EUID -eq 0 ]]; then
COLUSER=9 # root
else
COLUSER=112 # human
fi
local BKG1="\[\033[48;5;${COLUSER}m\]"
local FBKG1="\[\033[38;5;${COLUSER}m\]"
local BKG2="\[\033[48;5;11m\]"
local FBKG2="\[\033[38;5;11m\]"
local BOLD="\[$(tput bold)\]"
local FBLACK="\[\033[38;5;0m\]"
local FLIGHTBLUE="\[\033[38;5;159m\]" #195
local FLIGHTGRAY="\[\033[38;5;244m\]"
local ICON1="${BOLD}${FLIGHTBLUE}"
local ICON2="${BOLD}${FBLACK}${BKG2}"
local RESET="\[$(tput sgr0)\]" # "\[\033[0;39m\]"
local TEXT1="${RESET}${FLIGHTGRAY}"
local TEXT2="${RESET}${FBLACK}${BKG2}"
if [[ -n "$DESKTOP_SESSION" || -n "$REMOTE" ]] ; then
echo "\n${BKG1}${FBLACK}${ERRPROMPT} \u@\h${RESET}${FBKG1}▎${REMOTE}${ICON1}${TEXT1}\w ${ICON1}${TEXT1}\A\n${ICON2}${TEXT2}\W${RESET}${FBKG2}▎${BOLD}⌘${RESET} "
else
echo '[\u@\h \W]\$ '
fi
}
export PS1=`my_prompt`
所需的输出如下:
导航历史记录(按键向上/向下)并且有时按键Home时出现问题,我的光标位于不对应的位置或显示的文本覆盖提示或光标覆盖显示的文本。看到这张图片:
那么,问题出在哪里?为什么呢?解决方案是什么?提前谢谢。