Remove obsolete GIT_PROMPT_AUTO_PREFETCH option.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-25 15:25:14 +01:00
commit f856dfc18b

110
.bashrc
View file

@ -14,10 +14,7 @@ __prompt_git_status() {
# >> or >x - Working tree is ahead of upstream (x = commits ahead when used with next option). # >> or >x - Working tree is ahead of upstream (x = commits ahead when used with next option).
# << or <x - Working tree is behind upstream (x = commits behind when used with next option). # << or <x - Working tree is behind upstream (x = commits behind when used with next option).
# GIT_PROMPT_SHOW_UPSTREAM_EXTENDED=1 In addition to upstream status, show the number of commits difference (inplies above). # GIT_PROMPT_SHOW_UPSTREAM_EXTENDED=1 In addition to upstream status, show the number of commits difference (inplies above).
# GIT_PROMPT_AUTO_PREFETCH=1 Automatically 'prefetch' upstream refs for comparisons (requires GIT_PROMPT_SHOW_UPSTREAM above). # GIT_PROMPT_SHOW_IGNORED=1 Show a ! if the current directory is ignored, or _ if the git operation was timed out.
# This can be disabled on a per repository basis using:
# git config --add --bool maintenance.promptprefetchdisabled true
# GIT_PROMPT_SHOW_IGNORED=1 Show a ! if the current directory is ignored.
# GIT_PROMPT_SHOW_UNSTAGED=1 Show a * if there are unstaged changes (superceeded by above). # GIT_PROMPT_SHOW_UNSTAGED=1 Show a * if there are unstaged changes (superceeded by above).
# GIT_PROMPT_SHOW_UNCOMMITTED=1 Show a & if there are staged but uncommitted changes (superceeded by above). # GIT_PROMPT_SHOW_UNCOMMITTED=1 Show a & if there are staged but uncommitted changes (superceeded by above).
# GIT_PROMPT_SHOW_UNTRACKED=1 Show a + if there are untracked files in the working directory (superceeded by above). # GIT_PROMPT_SHOW_UNTRACKED=1 Show a + if there are untracked files in the working directory (superceeded by above).
@ -57,7 +54,7 @@ __prompt_git_status() {
# Add the branch or a no commits marker. # Add the branch or a no commits marker.
BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)" BRANCH="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
if [[ "$BRANCH" == "HEAD" ]]; then if [[ "$BRANCH" == "HEAD" ]]; then
GIT_PROMPT+="!NO COMMITS!" GIT_PROMPT+="?NO COMMITS?"
unset BRANCH unset BRANCH
else else
GIT_PROMPT+="$BRANCH" GIT_PROMPT+="$BRANCH"
@ -65,10 +62,6 @@ __prompt_git_status() {
# Add upstream status. # Add upstream status.
[[ -n "$GIT_PROMPT_SHOW_UPSTREAM" ]] || [[ -n "$GIT_PROMPT_SHOW_UPSTREAM_EXTENDED" ]] && { [[ -n "$GIT_PROMPT_SHOW_UPSTREAM" ]] || [[ -n "$GIT_PROMPT_SHOW_UPSTREAM_EXTENDED" ]] && {
# Whether to run prefetch tasks.
[[ -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:]' ' ')" COUNT="$(git rev-list --count --left-right "${BRANCH:+refs/prefetch/remotes/origin/}${BRANCH:-@{upstream\}}...HEAD" 2>/dev/null | tr '[:blank:]' ' ')"
case "$COUNT" in case "$COUNT" in
"") "")
@ -166,6 +159,24 @@ __prompt_user_colour() {
return "$RET" 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() { __nanorc_prompt_command() {
# Dynamically handle .nanorc file versions. # Dynamically handle .nanorc file versions.
hash nano >/dev/null 2>&1 && { 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_ssh_agent_sock() {
# Find an *active* ssh agent socket. # Find an *active* ssh agent socket.
# Returns: 0 = Found an active socket. # Returns: 0 = Found an active socket.
@ -364,45 +414,6 @@ __write_ssh_agents() {
return 0 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() { imagebin() {
[[ -z "$1" ]] && { [[ -z "$1" ]] && {
printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <filename>" >&2 printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <filename>" >&2
@ -431,13 +442,12 @@ history -a
history -r history -r
# The commands to execute before the prompt is displayed. # 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 options.
GIT_PROMPT_SHOW_TYPE=1 GIT_PROMPT_SHOW_TYPE=1
GIT_PROMPT_SHOW_UPSTREAM=1 GIT_PROMPT_SHOW_UPSTREAM=1
GIT_PROMPT_SHOW_UPSTREAM_EXTENDED=1 GIT_PROMPT_SHOW_UPSTREAM_EXTENDED=1
GIT_PROMPT_AUTO_PREFETCH=1
GIT_PROMPT_SHOW_IGNORED=1 GIT_PROMPT_SHOW_IGNORED=1
GIT_PROMPT_SHOW_UNSTAGED=1 GIT_PROMPT_SHOW_UNSTAGED=1
GIT_PROMPT_SHOW_UNCOMMITTED=1 GIT_PROMPT_SHOW_UNCOMMITTED=1