Clean up .bashrc.
This commit is contained in:
parent
f856dfc18b
commit
a84225d8f3
1 changed files with 36 additions and 31 deletions
43
.bashrc
43
.bashrc
|
@ -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).
|
# 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:
|
# Displays: The printf formatted git prompt based upon $1 and the environment vaiables above, for example:
|
||||||
# S:branch_name >5 *
|
# S:branch_name >5 *
|
||||||
# Returns: Exit code of the command line before entering this function.
|
# Returns: 0 = Produced a prompt successfully.
|
||||||
# shellcheck disable=SC2155
|
# 1 = An error occured.
|
||||||
local RET="$?" BRANCH COUNT GIT_PROMPT GIT_PROMPT_MARKER_SET GIT_REPO_INFO PWD=$(pwd -P)
|
local BRANCH COUNT GIT_PROMPT GIT_PROMPT_MARKER_SET GIT_REPO_INFO IFS=
|
||||||
|
|
||||||
# Bail out if there's no format argument given.
|
# Bail out if there's no format argument given, or it doesn't contain %s
|
||||||
(( $# != 1 )) && return "$RET"
|
(( $# != 1 )) || [[ "$1" != *%s* ]] && return 1
|
||||||
|
|
||||||
# Get some repository information.
|
# Get some repository information.
|
||||||
# shellcheck disable=SC2207
|
# 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) )
|
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
|
||||||
ERR="$?"
|
|
||||||
|
|
||||||
# Do nothing if there's an error.
|
|
||||||
(( ERR >= 1 )) && return "$RET"
|
|
||||||
|
|
||||||
# Generate the prompt.
|
# Generate the prompt.
|
||||||
if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then
|
if [[ "${GIT_REPO_INFO[2]}" == "true" ]]; then
|
||||||
|
@ -140,13 +136,11 @@ __prompt_git_status() {
|
||||||
# shellcheck disable=SC2059
|
# shellcheck disable=SC2059
|
||||||
printf -- "$1" "$GIT_PROMPT"
|
printf -- "$1" "$GIT_PROMPT"
|
||||||
|
|
||||||
# Return the original error code.
|
return 0
|
||||||
return "$RET"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__prompt_user_colour() {
|
__prompt_user_colour() {
|
||||||
# Determine the colour of the username in the prompt.
|
# Determine the colour of the username in the prompt.
|
||||||
local RET="$?"
|
|
||||||
|
|
||||||
if [[ "$LOGNAME" == "root" ]]; then
|
if [[ "$LOGNAME" == "root" ]]; then
|
||||||
printf "%s" "1;31m" # Bright Red.
|
printf "%s" "1;31m" # Bright Red.
|
||||||
|
@ -156,7 +150,7 @@ __prompt_user_colour() {
|
||||||
printf "%s" "1;36m" # Bright Cyan.
|
printf "%s" "1;36m" # Bright Cyan.
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return "$RET"
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
__git_prompt_command() {
|
__git_prompt_command() {
|
||||||
|
@ -165,20 +159,24 @@ __git_prompt_command() {
|
||||||
# GIT_DISABLE_PROMPT_PREFETCH=1 Disable automatic 'prefetch' of upstream refs.
|
# GIT_DISABLE_PROMPT_PREFETCH=1 Disable automatic 'prefetch' of upstream refs.
|
||||||
# This can also be disabled on a per repository basis using:
|
# This can also be disabled on a per repository basis using:
|
||||||
# git config --add --local --bool script.DisablePromptPrefetch true
|
# git config --add --local --bool script.DisablePromptPrefetch true
|
||||||
# Returns: Exit code of the command line before entering this function.
|
# Returns: 0 = Tasks completed successfully.
|
||||||
local RET="$?"
|
# 1 = An error occured.
|
||||||
|
|
||||||
# Run prefetch tasks if inside a work directory.
|
# Run prefetch tasks if inside a work directory.
|
||||||
[[ -z "$GIT_DISABLE_PROMPT_PREFETCH" ]] && [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" == "true" ]] && \
|
[[ -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 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() {
|
__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 && {
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
local NANO_VER="$(command nano --version | awk '/version/ { print $4 }' | cut -d. -f1)"
|
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
|
printf "\\033[1;31m%s\\033[39m\\n" "No .nanorc for version '$NANO_VER'." >&2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
__ssh_agent_prompt_command() {
|
__ssh_agent_prompt_command() {
|
||||||
|
@ -240,6 +240,7 @@ __ssh_agent_prompt_command() {
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,6 +331,7 @@ __read_ssh_agents() {
|
||||||
unset SSH_AUTH_SOCKS SSH_AGENTS_MTIME
|
unset SSH_AUTH_SOCKS SSH_AGENTS_MTIME
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
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
|
printf "\\033[1;31m%s\\033[39m\\n" "Failed to write ssh-agent socket list." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
imagebin() {
|
imagebin() {
|
||||||
[[ -z "$1" ]] && {
|
# Throw an image file into an imagebin.
|
||||||
|
|
||||||
|
[[ -z "$1" ]] || [[ ! -e "$1" ]] && {
|
||||||
printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <filename>" >&2
|
printf "%s: %s\\n" "Usage" "${FUNCNAME[0]} <filename>" >&2
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue