Update the prompt decorator for a modern iterm2
This commit is contained in:
parent
312aa84882
commit
37cd1750ab
1 changed files with 38 additions and 19 deletions
|
@ -1,26 +1,45 @@
|
|||
prompt-init() {
|
||||
local last_res=$? color=$PS1_color_success
|
||||
PS1="\w "
|
||||
###
|
||||
# Setup and decorate the prompt.
|
||||
###
|
||||
|
||||
if [[ -d .git ]]; then
|
||||
PS1+="$(command git branch --show-current) "
|
||||
fi
|
||||
prompt_symbol=λ
|
||||
prompt_color_fail=(204 80 83)
|
||||
prompt_color_pass=(48 92 161)
|
||||
|
||||
if [[ -v SSH_CLIENT ]]; then
|
||||
PS1+="$PS1_hostname "
|
||||
fi
|
||||
if hash git 2>/dev/null; then
|
||||
prompt_has_git=true
|
||||
fi
|
||||
|
||||
if (( last_res )); then
|
||||
color=$PS1_color_fail
|
||||
fi
|
||||
prompt_color_reset=$(tput sgr0)
|
||||
|
||||
PS1+="\[$color\][$last_res]\[$PS1_color_reset\] $PS1_prompt_sym "
|
||||
symbol-decorate() {
|
||||
local -n prompt_colors=$1
|
||||
local r=${prompt_colors[0]} g=${prompt_colors[1]} b=${prompt_colors[2]}
|
||||
printf '\e[38;2;%d;%d;%dm%s%s' "$r" "$g" "$b" "$prompt_symbol" "$(tput sgr0)"
|
||||
}
|
||||
|
||||
PROMPT_COMMAND+=(prompt-init)
|
||||
prompt-decorate() {
|
||||
local res=$? prompt_str
|
||||
|
||||
PS1_prompt_sym=λ
|
||||
PS1_hostname=${HOSTNAME-"$(hostname)"}
|
||||
PS1_color_fail=$(tput setaf 1)
|
||||
PS1_color_success=$(tput setaf 2)
|
||||
PS1_color_reset=$(tput sgr0)
|
||||
# prepend the
|
||||
if [[ -v SSH_CLIENT && -v HOSTNAME ]]; then
|
||||
prompt_str+=$HOSTNAME:
|
||||
fi
|
||||
|
||||
prompt_str+="\w "
|
||||
|
||||
if [[ -v prompt_has_git && -d .git ]]; then
|
||||
prompt_str+="$(command git branch --show-current) "
|
||||
fi
|
||||
|
||||
if (( res )); then
|
||||
prompt_str+=$(symbol-decorate prompt_color_fail)
|
||||
else
|
||||
prompt_str+=$(symbol-decorate prompt_color_pass)
|
||||
fi
|
||||
|
||||
prompt_str+="$(tput sgr0) "
|
||||
PS1=$prompt_str
|
||||
}
|
||||
|
||||
PROMPT_COMMAND+=(prompt-decorate)
|
||||
|
|
Loading…
Reference in a new issue