Skip to content

Commit

Permalink
p10k: update git status
Browse files Browse the repository at this point in the history
  • Loading branch information
geodimm committed Dec 13, 2024
1 parent 53bccf4 commit c2e4e5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
1 change: 1 addition & 0 deletions zsh/p10k/p10k.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
local fuchsia=13
local aqua=14
local white=15
# }}}

LC_COLLATE=C # sort files in ASCIIbetical order
for file in ~/dotfiles/zsh/p10k/segments/*; do
Expand Down
45 changes: 23 additions & 22 deletions zsh/p10k/segments/git.zsh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON='\uF126 '
typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
typeset -g POWERLEVEL9K_VCS_CLEAN_BACKGROUND=$black
typeset -g POWERLEVEL9K_VCS_MODIFIED_BACKGROUND=$black
typeset -g POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND=$black
Expand All @@ -21,55 +20,57 @@ function my_git_formatter() {
local modified='%F{yellow}' # yellow foreground
local untracked='%F{blue}' # blue foreground
local conflicted='%F{red}' # red foreground
local action='%F{purple}' # purple foreground
else
# Styling for incomplete and stale Git status.
local meta='%F{grey}' # grey foreground
local clean='%F{grey}' # grey foreground
local modified='%F{grey}' # grey foreground
local untracked='%F{grey}' # grey foreground
local conflicted='%F{grey}' # grey foreground
local action='%F{grey}' # grey foreground
fi

local res

if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
local branch=${(V)VCS_STATUS_LOCAL_BRANCH}
(( $#branch > 32 )) && branch[13,-13]="" # <-- this line
(( $#branch > 32 )) && branch[13,-13]=""
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${branch//\%/%%}"
fi

if [[ -n $VCS_STATUS_TAG
&& -z $VCS_STATUS_LOCAL_BRANCH # <-- this line
]]; then
if [[ -n $VCS_STATUS_TAG && -z $VCS_STATUS_LOCAL_BRANCH ]]; then
local tag=${(V)VCS_STATUS_TAG}
(( $#tag > 32 )) && tag[13,-13]="" # <-- this line
res+="${meta}#${clean}${tag//\%/%%}"
(( $#tag > 32 )) && tag[13,-13]=""
res+="${meta}󰓹 ${clean}${tag//\%/%%}"
fi

[[ -z $VCS_STATUS_LOCAL_BRANCH && -z $VCS_STATUS_TAG ]] && # <-- this line
res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}"
if [[ -z $VCS_STATUS_LOCAL_BRANCH && -z $VCS_STATUS_TAG ]]; then
res+="${meta}${clean}${VCS_STATUS_COMMIT[1,8]}"
fi

if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then
res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}"
fi

if [[ $VCS_STATUS_COMMIT_SUMMARY == (|*[^[:alnum:]])(wip|WIP)(|[^[:alnum:]]*) ]]; then
res+=" ${modified}wip"
res+=" ${modified}󰖷 "
fi

(( VCS_STATUS_COMMITS_BEHIND )) && res+=" ${clean}${VCS_STATUS_COMMITS_BEHIND}"
(( VCS_STATUS_COMMITS_AHEAD && !VCS_STATUS_COMMITS_BEHIND )) && res+=" "
(( VCS_STATUS_COMMITS_AHEAD )) && res+="${clean}${VCS_STATUS_COMMITS_AHEAD}"
integer num_staged_modified='VCS_STATUS_NUM_STAGED - VCS_STATUS_NUM_STAGED_NEW - VCS_STATUS_NUM_STAGED_DELETED'
(( VCS_STATUS_COMMITS_BEHIND )) && res+=" ${clean}${VCS_STATUS_COMMITS_BEHIND}"
(( VCS_STATUS_COMMITS_AHEAD )) && res+=" ${clean}${VCS_STATUS_COMMITS_AHEAD}"
(( VCS_STATUS_PUSH_COMMITS_BEHIND )) && res+=" ${clean}${VCS_STATUS_PUSH_COMMITS_BEHIND}"
(( VCS_STATUS_PUSH_COMMITS_AHEAD && !VCS_STATUS_PUSH_COMMITS_BEHIND )) && res+=" "
(( VCS_STATUS_PUSH_COMMITS_AHEAD )) && res+="${clean}${VCS_STATUS_PUSH_COMMITS_AHEAD}"
(( VCS_STATUS_STASHES )) && res+=" ${clean}*${VCS_STATUS_STASHES}"
[[ -n $VCS_STATUS_ACTION ]] && res+=" ${conflicted}${VCS_STATUS_ACTION}"
(( VCS_STATUS_NUM_CONFLICTED )) && res+=" ${conflicted}~${VCS_STATUS_NUM_CONFLICTED}"
(( VCS_STATUS_NUM_STAGED )) && res+=" ${modified}+${VCS_STATUS_NUM_STAGED}"
(( VCS_STATUS_NUM_UNSTAGED )) && res+=" ${modified}!${VCS_STATUS_NUM_UNSTAGED}"
(( VCS_STATUS_NUM_UNTRACKED )) && res+=" ${untracked}${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}${VCS_STATUS_NUM_UNTRACKED}"
(( VCS_STATUS_HAS_UNSTAGED == -1 )) && res+=" ${modified}"
(( VCS_STATUS_PUSH_COMMITS_AHEAD )) && res+=" ${clean}${VCS_STATUS_PUSH_COMMITS_AHEAD}"
(( VCS_STATUS_STASHES )) && res+=" ${clean}*${VCS_STATUS_STASHES}"
(( VCS_STATUS_ACTION )) && res+=" ${action}${VCS_STATUS_ACTION}"
(( VCS_STATUS_NUM_CONFLICTED )) && res+=" ${conflicted}~${VCS_STATUS_NUM_CONFLICTED}"
(( VCS_STATUS_NUM_STAGED_ADDED )) && res+=" ${clean}+${VCS_STATUS_NUM_STAGED_ADDED}"
(( VCS_STATUS_NUM_STAGED_DELETED )) && res+=" ${conflicted}-${VCS_STATUS_NUM_STAGED_DELETED}"
(( num_staged_modified )) && res+=" ${modified}~${num_staged_modified}"
(( VCS_STATUS_NUM_UNSTAGED )) && res+=" ${modified}!${VCS_STATUS_NUM_UNSTAGED}"
(( VCS_STATUS_NUM_UNTRACKED )) && res+=" ${untracked}?${VCS_STATUS_NUM_UNTRACKED}"
(( VCS_STATUS_HAS_UNSTAGED == -1 )) && res+=" ${modified}"

typeset -g my_git_format=$res
}
Expand Down

0 comments on commit c2e4e5a

Please sign in to comment.