Clean up .bashrc.

This commit is contained in:
Darren 'Tadgy' Austin 2023-10-25 16:05:55 +01:00
commit a84225d8f3

43
.bashrc
View file

@ -21,20 +21,16 @@ __prompt_git_status() {
# GIT_PROMPT_SHOW_STASH=1 Show a $ if there is a stash in this repository (superceeded by above).
# Displays: The printf formatted git prompt based upon $1 and the environment vaiables above, for example:
# S:branch_name >5 *
# Returns: Exit code of the command line before entering this function.
# shellcheck disable=SC2155
local RET="$?" BRANCH COUNT GIT_PROMPT GIT_PROMPT_MARKER_SET GIT_REPO_INFO PWD=$(pwd -P)
# Returns: 0 = Produced a prompt successfully.
# 1 = An error occured.
local BRANCH COUNT GIT_PROMPT GIT_PROMPT_MARKER_SET GIT_REPO_INFO IFS=
# Bail out if there's no format argument given.
(( $# != 1 )) && return "$RET"
# Bail out if there's no format argument given, or it doesn't contain %s
(( $# != 1 )) || [[ "$1" != *%s* ]] && return 1
# Get some repository information.
# shellcheck disable=SC2207
IFS=$'\n' GIT_REPO_INFO=( $( git rev-parse --is-bare-repository --is-shallow-repository --is-inside-git-dir --is-inside-work-tree 2>/dev/null) )
ERR="$?"
# Do nothing if there's an error.
(( ERR >= 1 )) && return "$RET"
GIT_REPO_INFO=( $( git rev-parse --is-bare-repository --is-shallow-repository --is-inside-git-dir --is-inside-work-tree 2>/dev/null) ) || return 1
# Generate the prompt.
if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then
@ -140,13 +136,11 @@ __prompt_git_status() {
# shellcheck disable=SC2059
printf -- "$1" "$GIT_PROMPT"
# Return the original error code.
return "$RET"
return 0
}
__prompt_user_colour() {
# Determine the colour of the username in the prompt.
local RET="$?"
if [[ "$LOGNAME" == "root" ]]; then
printf "%s" "1;31m" # Bright Red.
@ -156,7 +150,7 @@ __prompt_user_colour() {
printf "%s" "1;36m" # Bright Cyan.
fi
return "$RET"
return 0
}
__git_prompt_command() {
@ -165,20 +159,24 @@ __git_prompt_command() {
# 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="$?"
# Returns: 0 = Tasks completed successfully.
# 1 = An error occured.
# 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
git maintenance run --task=prefetch 2>/dev/null || {
printf "\\033[1;31m%s\\033[39m\\n" "Git maintenance 'prefetch' task failed." >&2
return 1
}
}
return "$RET"
return 0
}
__nanorc_prompt_command() {
# Dynamically handle .nanorc file versions.
hash nano >/dev/null 2>&1 && {
# shellcheck disable=SC2155
local NANO_VER="$(command nano --version | awk '/version/ { print $4 }' | cut -d. -f1)"
@ -202,6 +200,8 @@ __nanorc_prompt_command() {
printf "\\033[1;31m%s\\033[39m\\n" "No .nanorc for version '$NANO_VER'." >&2
fi
}
return 0
}
__ssh_agent_prompt_command() {
@ -240,6 +240,7 @@ __ssh_agent_prompt_command() {
sleep 0.5
fi
}
return 0
}
@ -330,6 +331,7 @@ __read_ssh_agents() {
unset SSH_AUTH_SOCKS SSH_AGENTS_MTIME
return 1
}
return 0
}
@ -411,11 +413,14 @@ __write_ssh_agents() {
printf "\\033[1;31m%s\\033[39m\\n" "Failed to write ssh-agent socket list." >&2
return 1
fi
return 0
}
imagebin() {
[[ -z "$1" ]] && {
# Throw an image file into an imagebin.
[[ -z "$1" ]] || [[ ! -e "$1" ]] && {
printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <filename>" >&2
return 1
}