diff --git a/lib/git.zsh b/lib/git.zsh index 118841f06..b2c5344da 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -12,6 +12,7 @@ function git_prompt_info() { parse_git_dirty() { local STATUS='' local FLAGS + local COPID='' FLAGS=('--porcelain') if [[ "$(command git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then if [[ $POST_1_7_2_GIT -gt 0 ]]; then @@ -20,12 +21,21 @@ parse_git_dirty() { if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then FLAGS+='--untracked-files=no' fi - STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1) - fi - if [[ -n $STATUS ]]; then - echo "$ZSH_THEME_GIT_PROMPT_DIRTY" - else - echo "$ZSH_THEME_GIT_PROMPT_CLEAN" + # Use coproc to timebox `git status` so slow repo access doesn't hang the prompt + # Use dummy "xxx" to distinguish timeouts from empty output + local END_OUTPUT="_end_of_status_" + coproc (command git status ${FLAGS} 2> /dev/null; echo $END_OUTPUT) + COPID=$! + read -p -t $ZSH_THEME_SCM_CHECK_TIMEOUT STATUS + if [[ -z $STATUS ]]; then + echo "$ZSH_THEME_GIT_PROMPT_TIMEDOUT" + # Get rid of that git run + kill -s KILL $COPID &>/dev/null + elif [[ $STATUS = $END_OUTPUT ]]; then + echo "$ZSH_THEME_GIT_PROMPT_CLEAN" + else + echo "$ZSH_THEME_GIT_PROMPT_DIRTY" + fi fi } diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 926303ca4..2c416b1c7 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -39,6 +39,11 @@ ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of th ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean +ZSH_THEME_GIT_PROMPT_TIMEDOUT="?" # Text to display if status check timed out + +# Timeout (in seconds, fractions OK) for SCM (git/hg/etc) info checks done +# inside prompt +ZSH_THEME_SCM_CHECK_TIMEOUT=1 # Setup the prompt with pretty colors setopt prompt_subst diff --git a/themes/robbyrussell.zsh-theme b/themes/robbyrussell.zsh-theme index 24e1e8c52..2da5658fa 100644 --- a/themes/robbyrussell.zsh-theme +++ b/themes/robbyrussell.zsh-theme @@ -4,4 +4,5 @@ PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(g ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗%{$reset_color%}" +ZSH_THEME_GIT_PROMPT_TIMEDOUT="%{$fg[blue]%}) %{$fg[red]%}?%{$reset_color%}" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"