From b67c763676d57cbddfd19c338f585221bd8731c6 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Fri, 20 Oct 2023 20:34:10 +0100 Subject: [PATCH] Sync .bashrc from master. --- .bashrc | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/.bashrc b/.bashrc index c1febf8..00bb621 100644 --- a/.bashrc +++ b/.bashrc @@ -26,7 +26,7 @@ __prompt_git_status() { # S:branch_name >5 * # Returns: Exit code of the command line before entering this function. # 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. (( $# != 1 )) && return "$RET" @@ -66,8 +66,7 @@ __prompt_git_status() { # Add upstream status. [[ -n "$GIT_PROMPT_SHOW_UPSTREAM" ]] || [[ -n "$GIT_PROMPT_SHOW_UPSTREAM_EXTENDED" ]] && { # Whether to run prefetch tasks. - [[ -n "$GIT_PROMPT_AUTO_PREFETCH" ]] && [[ "$PWD" == "${GIT_REPO_INFO[0]}" ]] && \ - [[ "$(git config --get --bool maintenance.promptprefetchdisabled 2>/dev/null)" != "true" ]] && { + [[ -n "$GIT_PROMPT_AUTO_PREFETCH" ]] && [[ "$(git config --get --bool maintenance.promptprefetchdisabled 2>/dev/null)" != "true" ]] && { git maintenance run --task=prefetch 2>/dev/null || printf "\\033[1;31m%s\\033[39m\\n" "Git maintenance 'prefetch' task failed." >&2 } COUNT="$(git rev-list --count --left-right "${BRANCH:+refs/prefetch/remotes/origin/}${BRANCH:-@{upstream\}}...HEAD" 2>/dev/null | tr '[:blank:]' ' ')" @@ -108,17 +107,40 @@ __prompt_git_status() { } # 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+=" !" - elif [[ -n "$GIT_PROMPT_SHOW_UNSTAGED" ]] && git ls-files --modified --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1; then - 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 + } + [[ -z "$GIT_PROMPT_MARKER_SET" ]] && [[ -n "$GIT_PROMPT_SHOW_UNSTAGED" ]] && { + timeout --signal=KILL 2s git ls-files --modified --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1 + ERR=$? + if (( ERR == 124 )) || (( ERR == 137 )); 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_UNCOMMITTED" ]] && ! git diff --name-only --cached --exit-code >/dev/null 2>&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_MARKER_SET=1 + } + [[ -z "$GIT_PROMPT_MARKER_SET" ]] && [[ -n "$GIT_PROMPT_SHOW_UNTRACKED" ]] && { + timeout --signal=KILL 2s git ls-files git ls-files --others --exclude-standard --directory --error-unmatch -- ':/*' >/dev/null 2>&1 + ERR=$? + if (( ERR == 124 )) || (( ERR == 137 )); 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+=" $" - fi + GIT_PROMPT_MARKER_SET=1 + } fi # Output the prompt. @@ -405,6 +427,7 @@ HISTFILESIZE=1000000 HISTIGNORE="bg:bg *:fg:fg *:jobs:exit:clear:history" HISTSIZE=1000000 HISTTIMEFORMAT="%d/%m/%y %H:%M:%S " +history -a history -r # The commands to execute before the prompt is displayed.