Use timeout to limit possibly long running git commands in some repos.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-20 20:15:03 +01:00
commit 9f60a6fde1

41
.bashrc
View file

@ -26,7 +26,7 @@ __prompt_git_status() {
# S:branch_name >5 * # S:branch_name >5 *
# Returns: Exit code of the command line before entering this function. # Returns: Exit code of the command line before entering this function.
# shellcheck disable=SC2155 # shellcheck disable=SC2155
local BRANCH COUNT GIT_PROMPT GIT_REPO_INFO PWD=$(pwd -P) RET="$?" local RET="$?" BRANCH COUNT GIT_PROMPT GIT_PROMPT_MARKER_SET GIT_REPO_INFO PWD=$(pwd -P)
# Bail out if there's no format argument given. # Bail out if there's no format argument given.
(( $# != 1 )) && return "$RET" (( $# != 1 )) && return "$RET"
@ -108,17 +108,40 @@ __prompt_git_status() {
} }
# Add a marker if directory is ignored, there's unstaged files, uncommitted changes, untracked files or a stash. # Add a marker if directory is ignored, there's unstaged files, uncommitted changes, untracked files or a stash.
if [[ -n "$GIT_PROMPT_SHOW_IGNORED" ]] && git check-ignore "${PWD#"${GIT_REPO_INFO[0]}/"}" >/dev/null 2>&1 ; then [[ -n "$GIT_PROMPT_SHOW_IGNORED" ]] && git check-ignore "${PWD#"${GIT_REPO_INFO[0]}/"}" >/dev/null 2>&1 && {
GIT_PROMPT+=" !" GIT_PROMPT+=" !"
elif [[ -n "$GIT_PROMPT_SHOW_UNSTAGED" ]] && git ls-files --modified --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1; then GIT_PROMPT_MARKER_SET=1
}
[[ -z "$GIT_PROMPT_MARKER_SET" ]] && [[ -n "$GIT_PROMPT_SHOW_UNSTAGED" ]] && {
timeout 2s git ls-files --modified --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1
ERR=$?
if (( ERR == 124 )); then
GIT_PROMPT+=" _"
GIT_PROMPT_MARKER_SET=1
elif (( ERR == 0 )); then
GIT_PROMPT+=" *" GIT_PROMPT+=" *"
elif [[ -n "$GIT_PROMPT_SHOW_UNCOMMITTED" ]] && ! git diff --name-only --cached --exit-code >/dev/null 2>&1; then GIT_PROMPT_MARKER_SET=1
GIT_PROMPT+=" &"
elif [[ -n "$GIT_PROMPT_SHOW_UNTRACKED" ]] && git ls-files --others --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1; then
GIT_PROMPT+=" +"
elif [[ -n "$GIT_PROMPT_SHOW_STASH" ]] && git rev-parse --verify --quiet refs/stash >/dev/null; then
GIT_PROMPT+=" $"
fi fi
}
[[ -z "$GIT_PROMPT_MARKER_SET" ]] && [[ -n "$GIT_PROMPT_SHOW_UNCOMMITTED" ]] && ! git diff --name-only --cached --exit-code >/dev/null 2>&1 && {
GIT_PROMPT+=" &"
GIT_PROMPT_MARKER_SET=1
}
[[ -z "$GIT_PROMPT_MARKER_SET" ]] && [[ -n "$GIT_PROMPT_SHOW_UNTRACKED" ]] && {
timeout 2s git ls-files git ls-files --others --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1
ERR=$?
if (( ERR == 124 )); then
GIT_PROMPT+=" _"
GIT_PROMPT_MARKER_SET=1
elif (( ERR == 0 )); then
GIT_PROMPT+=" +"
GIT_PROMPT_MARKER_SET=1
fi
}
[[ -z "$GIT_PROMPT_MARKER_SET" ]] && [[ -n "$GIT_PROMPT_SHOW_STASH" ]] && git rev-parse --verify --quiet refs/stash >/dev/null && {
GIT_PROMPT+=" $"
GIT_PROMPT_MARKER_SET=1
}
fi fi
# Output the prompt. # Output the prompt.