Files
dotfiles/zsh/theme

73 lines
2.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
git_branch_info() {
local git_status_full=$(git status --porcelain=v2 --branch -z 2>/dev/null)
[[ -n "$git_status_full" ]] || return
local branch=""
local status_indicators=""
local line
local -a status_lines=("${(0)git_status_full}")
for line in $status_lines; do
case $line in
\#' 'branch.head' '*) branch=${line##* }; continue ;;
\#' 'branch.ab' '*)
local -a counts=("${(s: :)line}")
[[ ${counts[3]#+} -gt 0 ]] && status_indicators+="%B%F{magenta}↑%f%b"
[[ ${counts[4]#-} -gt 0 ]] && status_indicators+="%B%F{green}↓%f%b"
;;
'?'*) ((untracked)) || { untracked=1; status_indicators+="%B%F{white}●%f%b" } ;;
'u'*) ((unmerged)) || { unmerged=1; status_indicators+="%B%F{red}✕%f%b" } ;;
[12]' '*)
if [[ ${line[3]} != "." && $staged -eq 0 ]]; then
staged=1
status_indicators+="%B%F{green}●%f%b"
fi
if [[ ${line[4]} != "." && $unstaged -eq 0 ]]; then
unstaged=1
status_indicators+="%B%F{red}●%f%b"
fi
;;
esac
done
[[ -n "$branch" ]] && echo " %B%F{white} %B%F{yellow}${branch}%f${status_indicators:+ $status_indicators}%B%F{white}%f "
}
local CACHED_PWD=""
local CACHED_SHORT_PWD=""
shrink_path() {
if [[ $CACHED_PWD != $PWD ]]; then
CACHED_PWD=$PWD
local directory=${PWD/#$HOME/\~}
if [[ $directory == '~' || $directory == '/' ]]; then
CACHED_SHORT_PWD=$directory
echo $CACHED_SHORT_PWD
return
fi
local parts=("${(@s:/:)directory}")
local output=()
for part in $parts[1,-2]; do
if [[ -n $part && $part != "~" ]]; then
output+=$part[1]
else
output+=$part
fi
done
output+=$parts[-1]
CACHED_SHORT_PWD=${(j:/:)output}
fi
echo $CACHED_SHORT_PWD
}
# SSH connection indicator
ssh_connection() {
if [[ -n $SSH_CONNECTION ]]; then
echo "%B%F{red}(ssh)%f%b "
fi
}
# Prompt configuration
PROMPT='$(ssh_connection)%B%F{green}%n@%m%f%b$(git_branch_info) %f%b: $(shrink_path)
[%(?:%B%F{green}%?%f%b:%B%F{red}%?%f%b)]  '
setopt PROMPT_SUBST