From f856dfc18bb53a3cef4e1bddd330d5997919dabb Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Wed, 25 Oct 2023 15:25:14 +0100 Subject: [PATCH] Remove obsolete GIT_PROMPT_AUTO_PREFETCH option. --- .bashrc | 110 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/.bashrc b/.bashrc index aae6553..77ff298 100644 --- a/.bashrc +++ b/.bashrc @@ -14,10 +14,7 @@ __prompt_git_status() { # >> or >x - Working tree is ahead of upstream (x = commits ahead when used with next option). # << or /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:]' ' ')" case "$COUNT" in "") @@ -166,6 +159,24 @@ __prompt_user_colour() { return "$RET" } +__git_prompt_command() { + # Perform git actions. + # Environment variables: + # GIT_DISABLE_PROMPT_PREFETCH=1 Disable automatic 'prefetch' of upstream refs. + # This can also be disabled on a per repository basis using: + # git config --add --local --bool script.DisablePromptPrefetch true + # Returns: Exit code of the command line before entering this function. + local RET="$?" + + # Run prefetch tasks if inside a work directory. + [[ -z "$GIT_DISABLE_PROMPT_PREFETCH" ]] && [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] && \ + [[ "$(git config --get --local --bool script.DisablePromptPrefetch 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 + } + + return "$RET" +} + __nanorc_prompt_command() { # Dynamically handle .nanorc file versions. hash nano >/dev/null 2>&1 && { @@ -193,6 +204,45 @@ __nanorc_prompt_command() { } } +__ssh_agent_prompt_command() { + # If necessary, find and activate a new ssh agent socket before each prompt is displayed. + # Returns: 0 = All is good. + # 1 = An error occured. + local ERR + + if [[ -z "$SSH_AUTH_SOCK" ]]; then + ERR=2 + else + ssh-add -l >/dev/null 2>&1 + ERR=$? + fi + (( ERR == 2 )) && { + # Read alternative sockets from ~/.ssh/agents. + __read_ssh_agents || { + unset SSH_AUTH_SOCK + return 1 + } + + # Find a new socket to use. + if __find_ssh_agent_sock; then + printf "\\033[1;33m%s\\033[39m\\n" "Connected to existing ssh-agent socket." + sleep 0.5 + else + # Start a new agent. + eval "$(ssh-agent -s 2>/dev/null | grep -v 'echo'; printf "%s" "ERR=${PIPESTATUS[0]}")" + (( ERR > 0 )) && { + printf "\\033[1;31m%s\\033[39m\\n" "Failed to start new ssh-agent - continuing with no agent." + sleep 0.5 + return 1 + } + printf "\\033[1;32m%s\\033[39m\\n" "Started new ssh-agent." + __write_ssh_agents + sleep 0.5 + fi + } + return 0 +} + __find_ssh_agent_sock() { # Find an *active* ssh agent socket. # Returns: 0 = Found an active socket. @@ -364,45 +414,6 @@ __write_ssh_agents() { return 0 } -__ssh_agent_prompt_command() { - # If necessary, find and activate a new ssh agent socket before each prompt is displayed. - # Returns: 0 = All is good. - # 1 = An error occured. - local ERR - - if [[ -z "$SSH_AUTH_SOCK" ]]; then - ERR=2 - else - ssh-add -l >/dev/null 2>&1 - ERR=$? - fi - (( ERR == 2 )) && { - # Read alternative sockets from ~/.ssh/agents. - __read_ssh_agents || { - unset SSH_AUTH_SOCK - return 1 - } - - # Find a new socket to use. - if __find_ssh_agent_sock; then - printf "\\033[1;33m%s\\033[39m\\n" "Connected to existing ssh-agent socket." - sleep 0.5 - else - # Start a new agent. - eval "$(ssh-agent -s 2>/dev/null | grep -v 'echo'; printf "%s" "ERR=${PIPESTATUS[0]}")" - (( ERR > 0 )) && { - printf "\\033[1;31m%s\\033[39m\\n" "Failed to start new ssh-agent - continuing with no agent." - sleep 0.5 - return 1 - } - printf "\\033[1;32m%s\\033[39m\\n" "Started new ssh-agent." - __write_ssh_agents - sleep 0.5 - fi - } - return 0 -} - imagebin() { [[ -z "$1" ]] && { printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} " >&2 @@ -431,13 +442,12 @@ history -a history -r # The commands to execute before the prompt is displayed. -PROMPT_COMMAND="__nanorc_prompt_command; __ssh_agent_prompt_command" +PROMPT_COMMAND="__nanorc_prompt_command; __ssh_agent_prompt_command; __git_prompt_command" # Git prompt options. GIT_PROMPT_SHOW_TYPE=1 GIT_PROMPT_SHOW_UPSTREAM=1 GIT_PROMPT_SHOW_UPSTREAM_EXTENDED=1 -GIT_PROMPT_AUTO_PREFETCH=1 GIT_PROMPT_SHOW_IGNORED=1 GIT_PROMPT_SHOW_UNSTAGED=1 GIT_PROMPT_SHOW_UNCOMMITTED=1