optimize zsh prompt
This commit is contained in:
45
zsh/.zshrc
45
zsh/.zshrc
@@ -113,32 +113,23 @@ precmd() {
|
||||
}
|
||||
zstyle ':vcs_info:git*' formats "%F{red}⎇ %b %F{blue}[%c%u] %F{240}(%F{red}%m%F{240})%f" # branch [staged unstaged(+untracked)] (misc(ahead/behind))
|
||||
|
||||
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
|
||||
+vi-git-untracked() {
|
||||
if [[ $(git rev-parse --is-inside-work-tree 2>/dev/null) == 'true' ]] &&
|
||||
git status --porcelain | grep -m1 --mmap '??' &>/dev/null; then
|
||||
hook_com[unstaged]+='?'
|
||||
zstyle ':vcs_info:git*+set-message:*' hooks git-extra
|
||||
|
||||
function +vi-git-extra() {
|
||||
# Only run these expensive operations in git repositories
|
||||
if [[ -n ${hook_com[branch]} ]]; then
|
||||
# Check if upstream exists before trying to get ahead/behind counts
|
||||
if git rev-parse --verify ${hook_com[branch]}@{upstream} >/dev/null 2>&1; then
|
||||
local ahead_behind=$(git rev-list --left-right --count HEAD...${hook_com[branch]}@{upstream} 2>/dev/null)
|
||||
local ahead=$(echo $ahead_behind | awk '{print $1}')
|
||||
local behind=$(echo $ahead_behind | awk '{print $2}')
|
||||
|
||||
[[ $ahead -gt 0 ]] && hook_com[misc]+="+"${ahead}
|
||||
[[ $behind -gt 0 ]] && hook_com[misc]+=${hook_com[misc]:+"/"}"-"${behind}
|
||||
fi
|
||||
|
||||
if [[ -n $(git ls-files --others --exclude-standard 2>/dev/null) ]]; then
|
||||
hook_com[unstaged]+='?'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
# zstyle ':vcs_info:git*+set-message:*' hooks git-st
|
||||
# function +vi-git-st() {
|
||||
# local ahead behind
|
||||
# local -a gitstatus
|
||||
#
|
||||
# # Exit early in case the worktree is on a detached HEAD
|
||||
# git rev-parse ${hook_com[branch]}@{upstream} >/dev/null 2>&1 || return 0
|
||||
#
|
||||
# local -a ahead_and_behind=(
|
||||
# $(git rev-list --left-right --count HEAD...${hook_com[branch]}@{upstream} 2>/dev/null)
|
||||
# )
|
||||
#
|
||||
# ahead=${ahead_and_behind[1]}
|
||||
# behind=${ahead_and_behind[2]}
|
||||
#
|
||||
# (( $ahead )) && gitstatus+=( "+${ahead}" )
|
||||
# (( $behind )) && gitstatus+=( "-${behind}" )
|
||||
#
|
||||
# # shfmt:ignore:start
|
||||
# hook_com[misc]+=${(j:/:)gitstatus}
|
||||
# # shfmt:ignore:end
|
||||
# }
|
||||
|
||||
Reference in New Issue
Block a user