refactor my_git_formatter to make it easier to change it so that tag is always displayed

pull/1173/head
Roman Perepelitsa 4 years ago
parent 4807bd8da2
commit a5d0525c6a

@ -379,29 +379,37 @@
fi fi
local res local res
local where # branch or tag
if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}" local branch=${(V)VCS_STATUS_LOCAL_BRANCH}
where=${(V)VCS_STATUS_LOCAL_BRANCH} # If local branch name is at most 32 characters long, show it in full.
elif [[ -n $VCS_STATUS_TAG ]]; then # Otherwise show the first 12 … the last 12.
res+="${meta}#" # Tip: To always show local branch name in full without truncation, delete the next line.
where=${(V)VCS_STATUS_TAG} (( $#branch > 32 )) && branch[13,-13]="…" # <-- this line
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${branch//\%/%%}"
fi fi
# If local branch name or tag is at most 32 characters long, show it in full. if [[ -n $VCS_STATUS_TAG
# Otherwise show the first 12 … the last 12. # Show tag only if not on a branch.
# Tip: To always show local branch name in full without truncation, delete the next line. # Tip: To always show tag, delete the next line.
(( $#where > 32 )) && where[13,-13]="…" && -z $VCS_STATUS_LOCAL_BRANCH # <-- this line
]]; then
res+="${clean}${where//\%/%%}" # escape % local tag=${(V)VCS_STATUS_TAG}
# If tag name is at most 32 characters long, show it in full.
# Otherwise show the first 12 … the last 12.
# Tip: To always show tag name in full without truncation, delete the next line.
(( $#tag > 32 )) && tag[13,-13]="…" # <-- this line
res+="${meta}#${clean}${tag//\%/%%}"
fi
# Display the current Git commit if there is no branch or tag. # Display the current Git commit if there is no branch and no tag.
# Tip: To always display the current Git commit, remove `[[ -z $where ]] &&` from the next line. # Tip: To always display the current Git commit, delete the next line.
[[ -z $where ]] && res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}" [[ -z $VCS_STATUS_LOCAL_BRANCH && -z $VCS_STATUS_LOCAL_BRANCH ]] && # <-- this line
res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}"
# Show tracking branch name if it differs from local branch. # Show tracking branch name if it differs from local branch.
if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then
res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}" # escape % res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}"
fi fi
# ⇣42 if behind the remote. # ⇣42 if behind the remote.

@ -377,29 +377,37 @@
fi fi
local res local res
local where # branch or tag
if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}" local branch=${(V)VCS_STATUS_LOCAL_BRANCH}
where=${(V)VCS_STATUS_LOCAL_BRANCH} # If local branch name is at most 32 characters long, show it in full.
elif [[ -n $VCS_STATUS_TAG ]]; then # Otherwise show the first 12 … the last 12.
res+="${meta}#" # Tip: To always show local branch name in full without truncation, delete the next line.
where=${(V)VCS_STATUS_TAG} (( $#branch > 32 )) && branch[13,-13]="…" # <-- this line
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${branch//\%/%%}"
fi fi
# If local branch name or tag is at most 32 characters long, show it in full. if [[ -n $VCS_STATUS_TAG
# Otherwise show the first 12 … the last 12. # Show tag only if not on a branch.
# Tip: To always show local branch name in full without truncation, delete the next line. # Tip: To always show tag, delete the next line.
(( $#where > 32 )) && where[13,-13]="…" && -z $VCS_STATUS_LOCAL_BRANCH # <-- this line
]]; then
res+="${clean}${where//\%/%%}" # escape % local tag=${(V)VCS_STATUS_TAG}
# If tag name is at most 32 characters long, show it in full.
# Otherwise show the first 12 … the last 12.
# Tip: To always show tag name in full without truncation, delete the next line.
(( $#tag > 32 )) && tag[13,-13]="…" # <-- this line
res+="${meta}#${clean}${tag//\%/%%}"
fi
# Display the current Git commit if there is no branch or tag. # Display the current Git commit if there is no branch and no tag.
# Tip: To always display the current Git commit, remove `[[ -z $where ]] &&` from the next line. # Tip: To always display the current Git commit, delete the next line.
[[ -z $where ]] && res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}" [[ -z $VCS_STATUS_LOCAL_BRANCH && -z $VCS_STATUS_LOCAL_BRANCH ]] && # <-- this line
res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}"
# Show tracking branch name if it differs from local branch. # Show tracking branch name if it differs from local branch.
if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then
res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}" # escape % res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}"
fi fi
# ⇣42 if behind the remote. # ⇣42 if behind the remote.

@ -373,29 +373,37 @@
fi fi
local res local res
local where # branch or tag
if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}" local branch=${(V)VCS_STATUS_LOCAL_BRANCH}
where=${(V)VCS_STATUS_LOCAL_BRANCH} # If local branch name is at most 32 characters long, show it in full.
elif [[ -n $VCS_STATUS_TAG ]]; then # Otherwise show the first 12 … the last 12.
res+="${meta}#" # Tip: To always show local branch name in full without truncation, delete the next line.
where=${(V)VCS_STATUS_TAG} (( $#branch > 32 )) && branch[13,-13]="…" # <-- this line
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${branch//\%/%%}"
fi fi
# If local branch name or tag is at most 32 characters long, show it in full. if [[ -n $VCS_STATUS_TAG
# Otherwise show the first 12 … the last 12. # Show tag only if not on a branch.
# Tip: To always show local branch name in full without truncation, delete the next line. # Tip: To always show tag, delete the next line.
(( $#where > 32 )) && where[13,-13]="…" && -z $VCS_STATUS_LOCAL_BRANCH # <-- this line
]]; then
res+="${clean}${where//\%/%%}" # escape % local tag=${(V)VCS_STATUS_TAG}
# If tag name is at most 32 characters long, show it in full.
# Otherwise show the first 12 … the last 12.
# Tip: To always show tag name in full without truncation, delete the next line.
(( $#tag > 32 )) && tag[13,-13]="…" # <-- this line
res+="${meta}#${clean}${tag//\%/%%}"
fi
# Display the current Git commit if there is no branch or tag. # Display the current Git commit if there is no branch and no tag.
# Tip: To always display the current Git commit, remove `[[ -z $where ]] &&` from the next line. # Tip: To always display the current Git commit, delete the next line.
[[ -z $where ]] && res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}" [[ -z $VCS_STATUS_LOCAL_BRANCH && -z $VCS_STATUS_LOCAL_BRANCH ]] && # <-- this line
res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}"
# Show tracking branch name if it differs from local branch. # Show tracking branch name if it differs from local branch.
if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then
res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}" # escape % res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}"
fi fi
# ⇣42 if behind the remote. # ⇣42 if behind the remote.

@ -380,29 +380,37 @@
local conflicted='%1F' # red foreground local conflicted='%1F' # red foreground
local res local res
local where # branch or tag
if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}" local branch=${(V)VCS_STATUS_LOCAL_BRANCH}
where=${(V)VCS_STATUS_LOCAL_BRANCH} # If local branch name is at most 32 characters long, show it in full.
elif [[ -n $VCS_STATUS_TAG ]]; then # Otherwise show the first 12 … the last 12.
res+="${meta}#" # Tip: To always show local branch name in full without truncation, delete the next line.
where=${(V)VCS_STATUS_TAG} (( $#branch > 32 )) && branch[13,-13]="…" # <-- this line
res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${branch//\%/%%}"
fi fi
# If local branch name or tag is at most 32 characters long, show it in full. if [[ -n $VCS_STATUS_TAG
# Otherwise show the first 12 … the last 12. # Show tag only if not on a branch.
# Tip: To always show local branch name in full without truncation, delete the next line. # Tip: To always show tag, delete the next line.
(( $#where > 32 )) && where[13,-13]="…" && -z $VCS_STATUS_LOCAL_BRANCH # <-- this line
]]; then
res+="${clean}${where//\%/%%}" # escape % local tag=${(V)VCS_STATUS_TAG}
# If tag name is at most 32 characters long, show it in full.
# Otherwise show the first 12 … the last 12.
# Tip: To always show tag name in full without truncation, delete the next line.
(( $#tag > 32 )) && tag[13,-13]="…" # <-- this line
res+="${meta}#${clean}${tag//\%/%%}"
fi
# Display the current Git commit if there is no branch or tag. # Display the current Git commit if there is no branch and no tag.
# Tip: To always display the current Git commit, remove `[[ -z $where ]] &&` from the next line. # Tip: To always display the current Git commit, delete the next line.
[[ -z $where ]] && res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}" [[ -z $VCS_STATUS_LOCAL_BRANCH && -z $VCS_STATUS_LOCAL_BRANCH ]] && # <-- this line
res+="${meta}@${clean}${VCS_STATUS_COMMIT[1,8]}"
# Show tracking branch name if it differs from local branch. # Show tracking branch name if it differs from local branch.
if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then if [[ -n ${VCS_STATUS_REMOTE_BRANCH:#$VCS_STATUS_LOCAL_BRANCH} ]]; then
res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}" # escape % res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}"
fi fi
# ⇣42 if behind the remote. # ⇣42 if behind the remote.

Loading…
Cancel
Save