Run git prefetch as PROMPT_COMMAND. Modify alias handling for Darwin.
This commit is contained in:
parent
5c761c9576
commit
2e9a893f28
1 changed files with 43 additions and 17 deletions
60
.bashrc
60
.bashrc
|
@ -158,19 +158,42 @@ __git_prompt_command() {
|
|||
# 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
|
||||
# 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
|
||||
|
||||
# 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 1
|
||||
# shellcheck disable=SC2207
|
||||
GIT_REPO_INFO=( $( git rev-parse --is-inside-work-tree --show-toplevel 2>/dev/null) ) || return 1
|
||||
|
||||
# Only process if in a work directory.
|
||||
[[ "${GIT_REPO_INFO[0]}" == "true" ]] && {
|
||||
# Run prefetch tasks if not disabled.
|
||||
[[ -z "$GIT_DISABLE_PROMPT_PREFETCH" ]] && [[ "$(git config --local --get --type 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 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# The time now.
|
||||
if [[ "$PLATFORM" == "Linux" ]]; then
|
||||
NOW="$(date +'%s%3N')"
|
||||
elif [[ "$PLATFORM" == "Darwin" ]]; then
|
||||
NOW="$(perl -e 'use Time::HiRes; printf "%.3f", Time::HiRes::time();')"
|
||||
NOW="${NOW/.}"
|
||||
fi
|
||||
|
||||
# FIXME: This is unfinished.
|
||||
|
||||
# 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"=
|
||||
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -481,17 +504,11 @@ export PS4='+(\[\033[1;33m\]$?\[\033[39m\]) \[\033[1;34m\]${BASH_SOURCE##*/}\[\0
|
|||
|
||||
# Common aliases.
|
||||
hash bc >/dev/null 2>&1 && alias bc='bc -lq'
|
||||
hash diff >/dev/null 2>&1 && alias diff='diff --color=auto -u'
|
||||
hash gpg2 >/dev/null 2>&1 && {
|
||||
alias gpg='command gpg2'
|
||||
alias gpg2='gpg2 --pinentry-mode=loopback'
|
||||
}
|
||||
hash grep >/dev/null 2>&1 && {
|
||||
alias egrep='grep -E --color=auto'
|
||||
alias fgrep='grep -F --color=auto'
|
||||
alias grep='grep --color=auto'
|
||||
}
|
||||
hash nc >/dev/null 2>&1 && alias pastebin='nc termbin.com 9999'
|
||||
|
||||
# Auto start the ssh agent and add keys for scp/sftp/ssh.
|
||||
__ssh_agent_prompt_command
|
||||
|
@ -529,7 +546,9 @@ if [[ "$PLATFORM" = "Linux" ]]; then
|
|||
}
|
||||
|
||||
# Linux specific aliases.
|
||||
hash diff >/dev/null 2>&1 && alias diff='diff --color=auto -u'
|
||||
hash ftpwho >/dev/null 2>&1 && alias ftpwho='ftpwho -v'
|
||||
hash gpg2 >/dev/null 2>&1 && alias gpg='command gpg2' && alias gpg2='gpg2 --pinentry-mode=loopback'
|
||||
hash iftop >/dev/null 2>&1 && alias iftop='TERM=vt100 iftop'
|
||||
hash iotop >/dev/null 2>&1 && alias iotop='TERM=linux iotop'
|
||||
hash ip >/dev/null 2>&1 && alias ip='ip -color=auto'
|
||||
|
@ -538,12 +557,19 @@ if [[ "$PLATFORM" = "Linux" ]]; then
|
|||
hash minicom >/dev/null 2>&1 && alias minicom='minicom -m -c on'
|
||||
hash mkpasswd >/dev/null 2>&1 && alias mkpasswd='mkpasswd -m sha512crypt'
|
||||
hash mkpasswd >/dev/null 2>&1 && alias pwgen='mkpasswd -m sha512crypt'
|
||||
hash nc >/dev/null 2>&1 && alias pastebin='nc termbin.com 9999'
|
||||
hash pinfo >/dev/null 2>&1 && alias info='pinfo'
|
||||
hash ping >/dev/null 2>&1 && alias ping='ping -b'
|
||||
elif [[ "$PLATFORM" = "Darwin" ]]; then
|
||||
# Darwin specific aliases.
|
||||
hash df >/dev/null 2>&1 && alias df='df -P'
|
||||
hash ls >/dev/null 2>&1 && alias ls='ls -bFG'
|
||||
# Darwin specific aliases (some dependant on macports)
|
||||
[[ ! -e "/opt/local/libexec/gnubin/df" ]] && alias df='df -kP'
|
||||
# shellcheck disable=SC2015
|
||||
[[ ! -e "/opt/local/libexec/gnubin//diff" ]] && alias diff='diff -u' || alias diff='diff --color=auto -u'
|
||||
hash last less >/dev/null 2>&1 && alias laston='last | less'
|
||||
# shellcheck disable=SC2015
|
||||
[[ ! -e "/opt/local/libexec/gnubin/ls" ]] && alias ls='ls -bFGO' || alias ls='ls -bFv --color=auto'
|
||||
[[ -e "/opt/local/libexec/gnubin/nc" ]] && alias pastebin='nc termbin.com 9999'
|
||||
[[ -e "/opt/local/bin/pinfo" ]] && alias info='pinfo'
|
||||
hash top >/dev/null 2>&1 && alias top='top -o cpu -S'
|
||||
else
|
||||
printf "%s: %s\\n" "${BASH_SOURCE##*/}" "unsupported platform: $PLATFORM" >&2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue