dotfiles/dotlib/generic-pre/prompt.sh

27 lines
530 B
Bash

setup-prompt() {
local last_res=$? color=$PS1_color_success
PS1="\w "
if [[ -d .git ]]; then
PS1+="$(command git branch --show-current) "
fi
if [[ -v SSH_CLIENT ]]; then
PS1+="$PS1_hostname "
fi
if (( last_res )); then
color=$PS1_color_fail
fi
PS1+="\[$color\][$last_res]\[$PS1_color_reset\] $PS1_prompt_sym "
}
PROMPT_COMMAND+=(setup-prompt)
PS1_prompt_sym=λ
PS1_hostname=${HOSTNAME-"$(hostname)"}
PS1_color_fail=$(tput setaf 1)
PS1_color_success=$(tput setaf 2)
PS1_color_reset=$(tput sgr0)