dotfiles/dotlib/generic-pre/prompt.sh

27 lines
528 B
Bash
Raw Normal View History

2022-10-25 00:34:42 +00:00
prompt-init() {
2022-10-25 00:24:06 +00:00
local last_res=$? color=$PS1_color_success
2022-10-21 21:33:38 +00:00
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
2022-10-25 00:24:06 +00:00
color=$PS1_color_fail
2022-10-21 21:33:38 +00:00
fi
PS1+="\[$color\][$last_res]\[$PS1_color_reset\] $PS1_prompt_sym "
}
2022-10-25 00:34:42 +00:00
PROMPT_COMMAND+=(prompt-init)
2022-10-25 00:24:06 +00:00
2022-10-21 21:33:38 +00:00
PS1_prompt_sym=λ
PS1_hostname=${HOSTNAME-"$(hostname)"}
2022-10-25 00:24:06 +00:00
PS1_color_fail=$(tput setaf 1)
PS1_color_success=$(tput setaf 2)
2022-10-21 21:33:38 +00:00
PS1_color_reset=$(tput sgr0)