Add git auto-merge reporting to prompt command.
This commit is contained in:
parent
2e9a893f28
commit
f0dcdf24f6
1 changed files with 33 additions and 8 deletions
41
.bashrc
41
.bashrc
|
|
@ -161,7 +161,7 @@ __git_prompt_command() {
|
|||
# git config ---local -replace-all --type bool script.DisablePromptPrefetch true
|
||||
# Returns: 0 = Tasks completed successfully.
|
||||
# 1 = An error occured.
|
||||
local GIT_REPO_INFO LC_ALL="C" NOW SANITISED_REPO
|
||||
local GIT_REPO_INFO LC_ALL="C" NOW REPO_TIMESTAMP SANITISED_REPO TIMESTAMP_VAR
|
||||
|
||||
# shellcheck disable=SC2207
|
||||
GIT_REPO_INFO=( $( git rev-parse --is-inside-work-tree --show-toplevel 2>/dev/null) ) || return 1
|
||||
|
|
@ -184,16 +184,41 @@ __git_prompt_command() {
|
|||
NOW="${NOW/.}"
|
||||
fi
|
||||
|
||||
# FIXME: This is unfinished.
|
||||
# Make sure the repo path is usable in a variable.
|
||||
SANITISED_REPO"${GIT_REPO_INFO[1]//[^[:alnum:]]/_}"
|
||||
|
||||
# SANITISED_REPO"${GIT_REPO_INFO[1]//[^[:alnum:]]/_}"
|
||||
# if (( BASH_VERSINFO[0] >= 4 )); then
|
||||
# else
|
||||
# TIMESTAMP_VAR="GIT_REPO_TIMESTAMP_$SANITISED_REPO"
|
||||
# [[ -z "${!TIMESTAMP_VAR}" ]] {
|
||||
# "GIT_REPO_TIMESTAMP_$SANITISED_REPO"=
|
||||
# Determine the timestamp variable name depending on bash version.
|
||||
if (( BASH_VERSINFO[0] >= 4 )); then
|
||||
TIMESTAMP_VAR="GIT_REPO_TIMESTAMP['$SANITISED_REPO']"
|
||||
else
|
||||
# This is going to pollute the environment, but Darwin is a PITA.
|
||||
TIMESTAMP_VAR="GIT_REPO_TIMESTAMP_$SANITISED_REPO"
|
||||
fi
|
||||
|
||||
if [[ -n "${!TIMESTAMP_VAR}" ]]; then
|
||||
# Monitor the git repo.
|
||||
REPO_TIMESTAMP="$(git config --local --get --type int script.AutoMergeLast)"
|
||||
(( ${!TIMESTAMP_VAR:-0} < REPO_TIMESTAMP )) && {
|
||||
# Display message depending on status.
|
||||
if [[ "$(git config --local --get --type int script.AutoMergeSuccess)" == "true" ]]; then
|
||||
printf "\\033[1;32m%s" "Git auto-merge succeeded for this repo."
|
||||
if [[ "${GIT_REPO_INFO[1]}" == "$HOME" ]]; then
|
||||
printf " %s\\033[39m\\n" "Re-source .bash* files."
|
||||
else
|
||||
printf "\\033[39m\\n"
|
||||
fi
|
||||
# Update the timestamp in the environment.
|
||||
declare -g "$TIMESTAMP_VAR"="$NOW"
|
||||
else
|
||||
printf "\\033[1;31m%s\\033[39m\\n" "Git auto-merge failed for this repo - correct manually." >&2
|
||||
fi
|
||||
}
|
||||
else
|
||||
# Just set the timestamp in the environment.
|
||||
declare -g "$TIMESTAMP_VAR"="$NOW"
|
||||
fi
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue