depot/config/zsh/components/theme-common-mod.zsh

89 lines
2.4 KiB
Bash
Raw Permalink Normal View History

2021-06-05 23:59:06 +03:00
# vim: filetype=sh
# Prompt symbol
COMMON_PROMPT_SYMBOL="Ψ"
# Colors
COMMON_COLORS_HOST_ME=green
COMMON_COLORS_HOST_AWS_VAULT=yellow
COMMON_COLORS_CURRENT_DIR=blue
COMMON_COLORS_RETURN_STATUS_TRUE=99
COMMON_COLORS_RETURN_STATUS_FALSE=red
COMMON_COLORS_GIT_STATUS_DEFAULT=green
COMMON_COLORS_GIT_STATUS_STAGED=red
COMMON_COLORS_GIT_STATUS_UNSTAGED=yellow
COMMON_COLORS_GIT_PROMPT_SHA=green
COMMON_COLORS_BG_JOBS=yellow
# Left Prompt
PROMPT='$(common_host)$(common_current_dir)$(common_bg_jobs)$(common_return_status)'
# Right Prompt
RPROMPT='$(common_git_status)'
# Prompt with current SHA
# PROMPT='$(common_host)$(common_current_dir)$(common_bg_jobs)$(common_return_status)'
# RPROMPT='$(common_git_status) $(git_prompt_short_sha)'
# Host
common_host() {
if [[ -n $SSH_CONNECTION ]]; then
me="%n@%m"
elif [[ $LOGNAME != $USER ]]; then
me="%n"
fi
if [[ -n $me ]]; then
echo "%{$fg[$COMMON_COLORS_HOST_ME]%}$me%{$reset_color%}:"
fi
if [[ $AWS_VAULT ]]; then
echo "%{$fg[$COMMON_COLORS_HOST_AWS_VAULT]%}$AWS_VAULT%{$reset_color%} "
fi
}
# Current directory
common_current_dir() {
echo -n "%{$fg[$COMMON_COLORS_CURRENT_DIR]%}%c "
}
# Prompt symbol
common_return_status() {
echo -n "%(?.%F{$COMMON_COLORS_RETURN_STATUS_TRUE}.%F{$COMMON_COLORS_RETURN_STATUS_FALSE})$COMMON_PROMPT_SYMBOL%f "
}
# Git status
common_git_status() {
local message=""
local message_color="%F{$COMMON_COLORS_GIT_STATUS_DEFAULT}"
# https://git-scm.com/docs/git-status#_short_format
local staged=$(git status --porcelain 2>/dev/null | grep -e "^[MADRCU]")
local unstaged=$(git status --porcelain 2>/dev/null | grep -e "^[MADRCU? ][MADRCU?]")
if [[ -n ${staged} ]]; then
message_color="%F{$COMMON_COLORS_GIT_STATUS_STAGED}"
elif [[ -n ${unstaged} ]]; then
message_color="%F{$COMMON_COLORS_GIT_STATUS_UNSTAGED}"
fi
local branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ -n ${branch} ]]; then
message+="${message_color}${branch}%f"
fi
echo -n "${message}"
}
# Git prompt SHA
ZSH_THEME_GIT_PROMPT_SHA_BEFORE="%{%F{$COMMON_COLORS_GIT_PROMPT_SHA}%}"
ZSH_THEME_GIT_PROMPT_SHA_AFTER="%{$reset_color%} "
# Background Jobs
common_bg_jobs() {
bg_status="%{$fg[$COMMON_COLORS_BG_JOBS]%}%(1j.↓%j .)"
echo -n $bg_status
}
# xterm title
PROMPT_XTITLE=$'%{\033]0;%n@%M:%~\007%}'
PROMPT="${PROMPT_XTITLE}${PROMPT}"