我正在运行 Ubuntu 18.04,我想设置我的 bash 提示,使其如下所示:
user:~/Documents [14:22:07] 1 $
Run Code Online (Sandbox Code Playgroud)
我的PS1如下:
ALERT_COLOR="$(tput setaf 1)"
# Display unsuccessful exit codes
function exit_status {
last_status=$?
if [[ $last_status != 0 ]]; then
echo "$ALERT_COLOR[$last_status]"
fi
}
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\] \[\033[36m\][\t] \[$ALERT_COLOR\]$exit_status \[\033[0;37m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt
Run Code Online (Sandbox Code Playgroud)
除了退出代码之外,一切都有效。它从不显示退出代码,如果我只是$?在我的 PS1 中这样做,那么它总是显示为0