replace expansion-based Git status formatter with a function

pull/260/head
romkatv 5 years ago
parent 1b0ac8a623
commit 2fd59f5acd

@ -314,65 +314,107 @@
#####################################[ vcs: git status ]###################################### #####################################[ vcs: git status ]######################################
# Branch icon. Set this parameter to '\uF126 ' for the popular Powerline branch icon. # Branch icon. Set this parameter to '\uF126 ' for the popular Powerline branch icon.
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON= typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
POWERLEVEL9K_VCS_BRANCH_ICON=${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}
# Untracked files icon. It's really a question mark, your font isn't broken. # Untracked files icon. It's really a question mark, your font isn't broken.
# Change the value of this parameter to show a different icon. # Change the value of this parameter to show a different icon.
typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?' typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
POWERLEVEL9K_VCS_UNTRACKED_ICON=${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}
# Git status: feature:master#tag ⇣42⇡42 *42 merge ~42 +42 !42 ?42. # Formatter for Git status.
# #
# You can edit the lines below to customize how Git status looks. # Example output: master ⇣42⇡42 *42 merge ~42 +42 !42 ?42.
# #
# VCS_STATUS parameters are set by gitstatus plugin. See reference: # You can edit the function to customize how Git status looks.
#
# VCS_STATUS_* parameters are set by gitstatus plugin. See reference:
# https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh. # https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh.
local vcs='' function my_git_formatter() {
# If on a branch... emulate -L zsh
vcs+='${${VCS_STATUS_LOCAL_BRANCH:+%76F'${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}
# If local branch name is at most 32 characters long, show it in full. if [[ -n $P9K_CONTENT ]]; then
# This is the equivalent of POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=32. # If P9K_CONTENT is not empty, use it. It's either "loading" or from vcs_info (not from
vcs+='${${${$(( ${#VCS_STATUS_LOCAL_BRANCH}<=32 )):#0}:+${VCS_STATUS_LOCAL_BRANCH//\%/%%}}' # gitstatus plugin). VCS_STATUS_* parameters are not available in this case.
# If local branch name is over 32 characters long, show the first 12 … the last 12. The same as typeset -g my_git_format=$P9K_CONTENT
# POWERLEVEL9K_VCS_SHORTEN_LENGTH=12 with POWERLEVEL9K_VCS_SHORTEN_STRATEGY=truncate_middle. return
vcs+=':-${${VCS_STATUS_LOCAL_BRANCH:0:12}//\%/%%}%28F…%76F${${VCS_STATUS_LOCAL_BRANCH: -12}//\%/%%}}}' fi
# '@72f5c8a' if not on a branch.
vcs+=':-%f@%76F${VCS_STATUS_COMMIT:0:8}}' if (( $1 )); then
# ':master' if the tracking branch name differs from local branch. # Styling for up-to-date Git status.
vcs+='${${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH}:+%f:%76F${VCS_STATUS_REMOTE_BRANCH//\%/%%}}' local meta='%f' # default foreground
# '#tag' if on a tag. local clean='%76F' # green foreground
vcs+='${VCS_STATUS_TAG:+%f#%76F${VCS_STATUS_TAG//\%/%%}}' local modified='%178F' # yellow foreground
# ⇣42 if behind the remote. local untracked='%39F' # blue foreground
vcs+='${${VCS_STATUS_COMMITS_BEHIND:#0}:+ %76F⇣${VCS_STATUS_COMMITS_BEHIND}}' local conflicted='%196F' # red foreground
# ⇡42 if ahead of the remote; no leading space if also behind the remote: ⇣42⇡42. local loading='%244F' # grey foreground
# If you want '⇣42 ⇡42' instead, replace '${${(M)VCS_STATUS_COMMITS_BEHIND:#0}:+ }' with ' '. else
vcs+='${${VCS_STATUS_COMMITS_AHEAD:#0}:+${${(M)VCS_STATUS_COMMITS_BEHIND:#0}:+ }%76F⇡${VCS_STATUS_COMMITS_AHEAD}}' # Styling for incomplete and stale Git status.
# *42 if have stashes. local meta='%244F' # grey foreground
vcs+='${${VCS_STATUS_STASHES:#0}:+ %76F*${VCS_STATUS_STASHES}}' local clean='%244F' # grey foreground
# 'merge' if the repo is in an unusual state. local modified='%244F' # grey foreground
vcs+='${VCS_STATUS_ACTION:+ %196F${VCS_STATUS_ACTION//\%/%%}}' local untracked='%244F' # grey foreground
# ~42 if have merge conflicts. local conflicted='%244F' # grey foreground
vcs+='${${VCS_STATUS_NUM_CONFLICTED:#0}:+ %196F~${VCS_STATUS_NUM_CONFLICTED}}' local loading='%244F' # grey foreground
# +42 if have staged changes. fi
vcs+='${${VCS_STATUS_NUM_STAGED:#0}:+ %178F+${VCS_STATUS_NUM_STAGED}}'
# !42 if have unstaged changes. local res
vcs+='${${VCS_STATUS_NUM_UNSTAGED:#0}:+ %178F!${VCS_STATUS_NUM_UNSTAGED}}' local where # branch name, tag or commit
# ?42 if have untracked files. It's really a question mark, your font isn't broken. if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
# See POWERLEVEL9K_VCS_UNTRACKED_ICON above if you want to use a different icon. res+="${clean}${POWERLEVEL9K_VCS_BRANCH_ICON}"
# Remove the next line if you don't want to see untracked files at all. where=${(V)VCS_STATUS_LOCAL_BRANCH}
vcs+='${${VCS_STATUS_NUM_UNTRACKED:#0}:+ %39F'${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}'${VCS_STATUS_NUM_UNTRACKED}}' elif [[ -n $VCS_STATUS_TAG ]]; then
# If P9K_CONTENT is not empty, leave it unchanged. It's either "loading" or from vcs_info. res+="${meta}#"
vcs="\${P9K_CONTENT:-$vcs}" where=${(V)VCS_STATUS_TAG}
else
res+="${meta}@"
where=${VCS_STATUS_COMMIT[1,8]}
fi
# If local branch name or tag is at most 32 characters long, show it in full.
# Otherwise show the first 12 … the last 12.
(( $#where > 32 )) && where[13,-13]="…"
res+="${clean}${where//\%/%%}" # escape %
# Show tracking branch name if it differs from local branch.
if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then
res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}" # escape %
fi
# ⇣42 if behind the remote.
(( VCS_STATUS_COMMITS_BEHIND )) && res+=" ${clean}${VCS_STATUS_COMMITS_BEHIND}"
# ⇡42 if ahead of the remote; no leading space if also behind the remote: ⇣42⇡42.
(( VCS_STATUS_COMMITS_AHEAD && !VCS_STATUS_COMMITS_BEHIND )) && res+=" "
(( VCS_STATUS_COMMITS_AHEAD )) && res+="${clean}${VCS_STATUS_COMMITS_AHEAD}"
# *42 if have stashes.
(( VCS_STATUS_STASHES )) && res+=" ${clean}*${VCS_STATUS_STASHES}"
# 'merge' if the repo is in an unusual state.
[[ -n $VCS_STATUS_ACTION ]] && res+=" ${conflicted}${VCS_STATUS_ACTION}"
# ~42 if have merge conflicts.
(( VCS_STATUS_NUM_CONFLICTED )) && res+=" ${conflicted}~${VCS_STATUS_NUM_CONFLICTED}"
# +42 if have staged changes.
(( VCS_STATUS_NUM_STAGED )) && res+=" ${modified}+${VCS_STATUS_NUM_STAGED}"
# !42 if have unstaged changes.
(( VCS_STATUS_NUM_UNSTAGED )) && res+=" ${modified}!${VCS_STATUS_NUM_UNSTAGED}"
# ?42 if have untracked files. It's really a question mark, your font isn't broken.
# See POWERLEVEL9K_VCS_UNTRACKED_ICON above if you want to use a different icon.
# Remove the next line if you don't want to see untracked files at all.
(( VCS_STATUS_NUM_UNTRACKED )) && res+=" ${untracked}${POWERLEVEL9K_VCS_UNTRACKED_ICON}${VCS_STATUS_NUM_UNTRACKED}"
typeset -g my_git_format=$res
}
functions +M -m my_git_formatter && functions -M my_git_formatter
# Disable the default Git status formatting. # Disable the default Git status formatting.
typeset -g POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING=true typeset -g POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING=true
# Install our own Git status formatter. # Install our own Git status formatter.
typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION=$vcs typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION='${$((my_git_formatter(1)))+${my_git_format}}'
# When Git status is being refreshed asynchronously, display the last known repo status in grey. typeset -g POWERLEVEL9K_VCS_LOADING_CONTENT_EXPANSION='${$((my_git_formatter(0)))+${my_git_format}}'
typeset -g POWERLEVEL9K_VCS_LOADING_CONTENT_EXPANSION=${${${vcs//\%f}//\%<->F}//\%F\{(\#|)[[:xdigit:]]#(\\|)\}}
# Enable counters for staged, unstaged, etc. # Enable counters for staged, unstaged, etc.
typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED,CONFLICTED,COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=-1 typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED,CONFLICTED,COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=-1
# Icon color. # Icon color.
typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_COLOR=76 typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_COLOR=76
typeset -g POWERLEVEL9K_VCS_LOADING_VISUAL_IDENTIFIER_COLOR=244
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_EXPANSION='⭐'
# Custom prefix. # Custom prefix.
@ -383,7 +425,6 @@
# isn't in an svn or hg reposotiry. # isn't in an svn or hg reposotiry.
typeset -g POWERLEVEL9K_VCS_BACKENDS=(git) typeset -g POWERLEVEL9K_VCS_BACKENDS=(git)
typeset -g POWERLEVEL9K_VCS_LOADING_FOREGROUND=246
# These settings are used for respositories other than Git or when gitstatusd fails and # These settings are used for respositories other than Git or when gitstatusd fails and
# Powerlevel10k has to fall back to using vcs_info. # Powerlevel10k has to fall back to using vcs_info.
typeset -g POWERLEVEL9K_VCS_CLEAN_FOREGROUND=76 typeset -g POWERLEVEL9K_VCS_CLEAN_FOREGROUND=76

@ -294,65 +294,107 @@
#####################################[ vcs: git status ]###################################### #####################################[ vcs: git status ]######################################
# Branch icon. Set this parameter to '\uF126 ' for the popular Powerline branch icon. # Branch icon. Set this parameter to '\uF126 ' for the popular Powerline branch icon.
typeset -g POWERLEVEL9K_VCS_BRANCH_ICON= typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
POWERLEVEL9K_VCS_BRANCH_ICON=${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}
# Untracked files icon. It's really a question mark, your font isn't broken. # Untracked files icon. It's really a question mark, your font isn't broken.
# Change the value of this parameter to show a different icon. # Change the value of this parameter to show a different icon.
typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?' typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
POWERLEVEL9K_VCS_UNTRACKED_ICON=${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}
# Git status: feature:master#tag ⇣42⇡42 *42 merge ~42 +42 !42 ?42. # Formatter for Git status.
# #
# You can edit the lines below to customize how Git status looks. # Example output: master ⇣42⇡42 *42 merge ~42 +42 !42 ?42.
# #
# VCS_STATUS parameters are set by gitstatus plugin. See reference: # You can edit the function to customize how Git status looks.
#
# VCS_STATUS_* parameters are set by gitstatus plugin. See reference:
# https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh. # https://github.com/romkatv/gitstatus/blob/master/gitstatus.plugin.zsh.
local vcs='' function my_git_formatter() {
# If on a branch... emulate -L zsh
vcs+='${${VCS_STATUS_LOCAL_BRANCH:+%76F'${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}
# If local branch name is at most 32 characters long, show it in full. if [[ -n $P9K_CONTENT ]]; then
# This is the equivalent of POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=32. # If P9K_CONTENT is not empty, use it. It's either "loading" or from vcs_info (not from
vcs+='${${${$(( ${#VCS_STATUS_LOCAL_BRANCH}<=32 )):#0}:+${VCS_STATUS_LOCAL_BRANCH//\%/%%}}' # gitstatus plugin). VCS_STATUS_* parameters are not available in this case.
# If local branch name is over 32 characters long, show the first 12 … the last 12. The same as typeset -g my_git_format=$P9K_CONTENT
# POWERLEVEL9K_VCS_SHORTEN_LENGTH=12 with POWERLEVEL9K_VCS_SHORTEN_STRATEGY=truncate_middle. return
vcs+=':-${${VCS_STATUS_LOCAL_BRANCH:0:12}//\%/%%}%28F…%76F${${VCS_STATUS_LOCAL_BRANCH: -12}//\%/%%}}}' fi
# '@72f5c8a' if not on a branch.
vcs+=':-%f@%76F${VCS_STATUS_COMMIT:0:8}}' if (( $1 )); then
# ':master' if the tracking branch name differs from local branch. # Styling for up-to-date Git status.
vcs+='${${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH}:+%f:%76F${VCS_STATUS_REMOTE_BRANCH//\%/%%}}' local meta='%f' # default foreground
# '#tag' if on a tag. local clean='%76F' # green foreground
vcs+='${VCS_STATUS_TAG:+%f#%76F${VCS_STATUS_TAG//\%/%%}}' local modified='%178F' # yellow foreground
# ⇣42 if behind the remote. local untracked='%39F' # blue foreground
vcs+='${${VCS_STATUS_COMMITS_BEHIND:#0}:+ %76F⇣${VCS_STATUS_COMMITS_BEHIND}}' local conflicted='%196F' # red foreground
# ⇡42 if ahead of the remote; no leading space if also behind the remote: ⇣42⇡42. local loading='%244F' # grey foreground
# If you want '⇣42 ⇡42' instead, replace '${${(M)VCS_STATUS_COMMITS_BEHIND:#0}:+ }' with ' '. else
vcs+='${${VCS_STATUS_COMMITS_AHEAD:#0}:+${${(M)VCS_STATUS_COMMITS_BEHIND:#0}:+ }%76F⇡${VCS_STATUS_COMMITS_AHEAD}}' # Styling for incomplete and stale Git status.
# *42 if have stashes. local meta='%244F' # grey foreground
vcs+='${${VCS_STATUS_STASHES:#0}:+ %76F*${VCS_STATUS_STASHES}}' local clean='%244F' # grey foreground
# 'merge' if the repo is in an unusual state. local modified='%244F' # grey foreground
vcs+='${VCS_STATUS_ACTION:+ %196F${VCS_STATUS_ACTION//\%/%%}}' local untracked='%244F' # grey foreground
# ~42 if have merge conflicts. local conflicted='%244F' # grey foreground
vcs+='${${VCS_STATUS_NUM_CONFLICTED:#0}:+ %196F~${VCS_STATUS_NUM_CONFLICTED}}' local loading='%244F' # grey foreground
# +42 if have staged changes. fi
vcs+='${${VCS_STATUS_NUM_STAGED:#0}:+ %178F+${VCS_STATUS_NUM_STAGED}}'
# !42 if have unstaged changes. local res
vcs+='${${VCS_STATUS_NUM_UNSTAGED:#0}:+ %178F!${VCS_STATUS_NUM_UNSTAGED}}' local where # branch name, tag or commit
# ?42 if have untracked files. It's really a question mark, your font isn't broken. if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
# See POWERLEVEL9K_VCS_UNTRACKED_ICON above if you want to use a different icon. res+="${clean}${POWERLEVEL9K_VCS_BRANCH_ICON}"
# Remove the next line if you don't want to see untracked files at all. where=${(V)VCS_STATUS_LOCAL_BRANCH}
vcs+='${${VCS_STATUS_NUM_UNTRACKED:#0}:+ %39F'${(g::)POWERLEVEL9K_VCS_UNTRACKED_ICON}'${VCS_STATUS_NUM_UNTRACKED}}' elif [[ -n $VCS_STATUS_TAG ]]; then
# If P9K_CONTENT is not empty, leave it unchanged. It's either "loading" or from vcs_info. res+="${meta}#"
vcs="\${P9K_CONTENT:-$vcs}" where=${(V)VCS_STATUS_TAG}
else
res+="${meta}@"
where=${VCS_STATUS_COMMIT[1,8]}
fi
# If local branch name or tag is at most 32 characters long, show it in full.
# Otherwise show the first 12 … the last 12.
(( $#where > 32 )) && where[13,-13]="…"
res+="${clean}${where//\%/%%}" # escape %
# Show tracking branch name if it differs from local branch.
if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then
res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}" # escape %
fi
# ⇣42 if behind the remote.
(( VCS_STATUS_COMMITS_BEHIND )) && res+=" ${clean}${VCS_STATUS_COMMITS_BEHIND}"
# ⇡42 if ahead of the remote; no leading space if also behind the remote: ⇣42⇡42.
(( VCS_STATUS_COMMITS_AHEAD && !VCS_STATUS_COMMITS_BEHIND )) && res+=" "
(( VCS_STATUS_COMMITS_AHEAD )) && res+="${clean}${VCS_STATUS_COMMITS_AHEAD}"
# *42 if have stashes.
(( VCS_STATUS_STASHES )) && res+=" ${clean}*${VCS_STATUS_STASHES}"
# 'merge' if the repo is in an unusual state.
[[ -n $VCS_STATUS_ACTION ]] && res+=" ${conflicted}${VCS_STATUS_ACTION}"
# ~42 if have merge conflicts.
(( VCS_STATUS_NUM_CONFLICTED )) && res+=" ${conflicted}~${VCS_STATUS_NUM_CONFLICTED}"
# +42 if have staged changes.
(( VCS_STATUS_NUM_STAGED )) && res+=" ${modified}+${VCS_STATUS_NUM_STAGED}"
# !42 if have unstaged changes.
(( VCS_STATUS_NUM_UNSTAGED )) && res+=" ${modified}!${VCS_STATUS_NUM_UNSTAGED}"
# ?42 if have untracked files. It's really a question mark, your font isn't broken.
# See POWERLEVEL9K_VCS_UNTRACKED_ICON above if you want to use a different icon.
# Remove the next line if you don't want to see untracked files at all.
(( VCS_STATUS_NUM_UNTRACKED )) && res+=" ${untracked}${POWERLEVEL9K_VCS_UNTRACKED_ICON}${VCS_STATUS_NUM_UNTRACKED}"
typeset -g my_git_format=$res
}
functions +M -m my_git_formatter && functions -M my_git_formatter
# Disable the default Git status formatting. # Disable the default Git status formatting.
typeset -g POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING=true typeset -g POWERLEVEL9K_VCS_DISABLE_GITSTATUS_FORMATTING=true
# Install our own Git status formatter. # Install our own Git status formatter.
typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION=$vcs typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION='${$((my_git_formatter(1)))+${my_git_format}}'
# When Git status is being refreshed asynchronously, display the last known repo status in grey. typeset -g POWERLEVEL9K_VCS_LOADING_CONTENT_EXPANSION='${$((my_git_formatter(0)))+${my_git_format}}'
typeset -g POWERLEVEL9K_VCS_LOADING_CONTENT_EXPANSION=${${${vcs//\%f}//\%<->F}//\%F\{(\#|)[[:xdigit:]]#(\\|)\}}
# Enable counters for staged, unstaged, etc. # Enable counters for staged, unstaged, etc.
typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED,CONFLICTED,COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=-1 typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED,CONFLICTED,COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=-1
# Icon color. # Icon color.
typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_COLOR=76 typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_COLOR=76
typeset -g POWERLEVEL9K_VCS_LOADING_VISUAL_IDENTIFIER_COLOR=244
# Custom icon. # Custom icon.
# typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_EXPANSION='⭐' # typeset -g POWERLEVEL9K_VCS_VISUAL_IDENTIFIER_EXPANSION='⭐'
# Custom prefix. # Custom prefix.
@ -363,7 +405,6 @@
# isn't in an svn or hg reposotiry. # isn't in an svn or hg reposotiry.
typeset -g POWERLEVEL9K_VCS_BACKENDS=(git) typeset -g POWERLEVEL9K_VCS_BACKENDS=(git)
typeset -g POWERLEVEL9K_VCS_LOADING_FOREGROUND=244
# These settings are used for respositories other than Git or when gitstatusd fails and # These settings are used for respositories other than Git or when gitstatusd fails and
# Powerlevel10k has to fall back to using vcs_info. # Powerlevel10k has to fall back to using vcs_info.
typeset -g POWERLEVEL9K_VCS_CLEAN_FOREGROUND=76 typeset -g POWERLEVEL9K_VCS_CLEAN_FOREGROUND=76

Loading…
Cancel
Save