34 lines
778 B
Bash
34 lines
778 B
Bash
|
GIT_BRANCH=
|
||
|
GIT_BG_PID=0
|
||
|
|
||
|
trap 'git_callback' USR1
|
||
|
|
||
|
get_git_branch () {
|
||
|
git rev-parse --abbrev-ref HEAD 2> /dev/null > "/tmp/zsh_git_branch.$$"
|
||
|
# git rev-parse --verify REBASE_HEAD 2> /dev/null && echo 1 > "/tmp/zsh_git_rebase.$$"
|
||
|
kill -s USR1 $$ > /dev/null 2> /dev/null
|
||
|
}
|
||
|
|
||
|
git_branch_bg () {
|
||
|
if [[ $GIT_BG_PID != 0 ]]; then
|
||
|
kill -s HUP $GIT_BG_PID > /dev/null 2>&1
|
||
|
fi
|
||
|
if [ -f "/tmp/zsh_git_branch.$$" ]; then
|
||
|
rm "/tmp/zsh_git_branch.$$"
|
||
|
fi
|
||
|
get_git_branch &!
|
||
|
GIT_BG_PID=$!
|
||
|
}
|
||
|
|
||
|
git_callback () {
|
||
|
GIT_BRANCH=$(cat "/tmp/zsh_git_branch.$$")
|
||
|
rm "/tmp/zsh_git_branch.$$"
|
||
|
update_right_prompt
|
||
|
GIT_BG_PID=0
|
||
|
}
|
||
|
|
||
|
autoload -U add-zsh-hook
|
||
|
# add-zsh-hook chpwd git_branch_bg
|
||
|
add-zsh-hook precmd git_branch_bg
|
||
|
git_branch_bg
|