mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-23 02:35:38 +01:00
fix: ensure git branch name appears in prompt on all systems
This commit is contained in:
parent
ec14da72fb
commit
4b9d5b861d
1 changed files with 18 additions and 2 deletions
20
lib/git.zsh
20
lib/git.zsh
|
|
@ -149,31 +149,43 @@ if zstyle -t ':omz:alpha:lib:git' async-prompt \
|
||||||
function git_prompt_info() {
|
function git_prompt_info() {
|
||||||
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" ]]; then
|
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" ]]; then
|
||||||
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}"
|
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}"
|
||||||
|
elif __git_prompt_git rev-parse --git-dir &> /dev/null; then
|
||||||
|
_omz_git_prompt_info
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_prompt_status() {
|
function git_prompt_status() {
|
||||||
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" ]]; then
|
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" ]]; then
|
||||||
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}"
|
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}"
|
||||||
|
elif __git_prompt_git rev-parse --git-dir &> /dev/null; then
|
||||||
|
_omz_git_prompt_status
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Conditionally register the async handler, only if it's needed in $PROMPT
|
# Conditionally register the async handler, only if it's needed in $PROMPT
|
||||||
# or any of the other prompt variables
|
# or any of the other prompt variables
|
||||||
function _defer_async_git_register() {
|
function _defer_async_git_register() {
|
||||||
|
local prompt_vars="${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}:${PROMPT}"
|
||||||
|
local registered=0
|
||||||
|
|
||||||
# Check if git_prompt_info is used in a prompt variable
|
# Check if git_prompt_info is used in a prompt variable
|
||||||
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
|
case "$prompt_vars" in
|
||||||
*(\$\(git_prompt_info\)|\`git_prompt_info\`)*)
|
*(\$\(git_prompt_info\)|\`git_prompt_info\`)*)
|
||||||
_omz_register_handler _omz_git_prompt_info
|
_omz_register_handler _omz_git_prompt_info
|
||||||
|
registered=1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "${PS1}:${PS2}:${PS3}:${PS4}:${RPROMPT}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
|
case "$prompt_vars" in
|
||||||
*(\$\(git_prompt_status\)|\`git_prompt_status\`)*)
|
*(\$\(git_prompt_status\)|\`git_prompt_status\`)*)
|
||||||
_omz_register_handler _omz_git_prompt_status
|
_omz_register_handler _omz_git_prompt_status
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
if (( ! registered )) && __git_prompt_git rev-parse --git-dir &> /dev/null; then
|
||||||
|
_omz_register_handler _omz_git_prompt_info
|
||||||
|
fi
|
||||||
|
|
||||||
add-zsh-hook -d precmd _defer_async_git_register
|
add-zsh-hook -d precmd _defer_async_git_register
|
||||||
unset -f _defer_async_git_register
|
unset -f _defer_async_git_register
|
||||||
}
|
}
|
||||||
|
|
@ -185,12 +197,16 @@ elif zstyle -s ':omz:alpha:lib:git' async-prompt _style && [[ $_style == "force"
|
||||||
function git_prompt_info() {
|
function git_prompt_info() {
|
||||||
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" ]]; then
|
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" ]]; then
|
||||||
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}"
|
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}"
|
||||||
|
elif __git_prompt_git rev-parse --git-dir &> /dev/null; then
|
||||||
|
_omz_git_prompt_info
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_prompt_status() {
|
function git_prompt_status() {
|
||||||
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" ]]; then
|
if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" ]]; then
|
||||||
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}"
|
echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}"
|
||||||
|
elif __git_prompt_git rev-parse --git-dir &> /dev/null; then
|
||||||
|
_omz_git_prompt_status
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue