1
0
mirror of https://github.com/akelge/zsh synced 2025-07-03 05:05:28 +00:00

Fixes for OMP prompts and for default PATH

This commit is contained in:
2021-12-17 09:14:01 +01:00
parent 0ae9cfdb9e
commit 51bd0516d6
8 changed files with 185 additions and 13 deletions

View File

@ -21,8 +21,6 @@ if [ $profile ]; then # We got a profile pattern, look for a match
print -P "$FX[bold]activating profile $FG[075]$match$FX[reset]"
export AWS_DEFAULT_PROFILE=$match
export AWS_PROFILE=$match
export AWS_DEFAULT_REGION=$(grep -A1 $match ~/.aws/config|grep region|cut -d" " -f3)
export AWS_REGION=${AWS_DEFAULT_REGION}
return
else
print -P "$FX[bold]$FG[009]no match for $profile$FX[reset]"
@ -30,7 +28,7 @@ if [ $profile ]; then # We got a profile pattern, look for a match
fi
elif [ $AWS_PROFILE ]; then # no profile passed, clean up current one, logout
unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_DEFAULT_REGION AWS_REGION
unset AWS_DEFAULT_PROFILE AWS_PROFILE
print -P "$FX[bold]profile cleared$FX[reset]."
return
fi

View File

@ -7,7 +7,60 @@ cd $1
gitdir=$(git rev-parse --git-dir 2> /dev/null) || return 0
last_fetch=$(zstat +mtime $gitdir/FETCH_HEAD 2> /dev/null || echo 0)
let "diff = $(strftime %s) - $last_fetch"
[ $diff -gt ${GIT_FETCH_INTERVAL:-30} ] && git fetch --all -p
if [ $diff -gt ${GIT_FETCH_INTERVAL:-30} ]; then
setopt localoptions noshwordsplit
# Sets `GIT_TERMINAL_PROMPT=0` to disable authentication prompt for Git fetch (Git 2.3+).
export GIT_TERMINAL_PROMPT=0
# Set SSH `BachMode` to disable all interactive SSH password prompting.
export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-"ssh"} -o BatchMode=yes"
local ref
ref=$(command git symbolic-ref -q HEAD)
local -a remote
remote=($(command git for-each-ref --format='%(upstream:remotename) %(refname)' $ref))
if [[ -z $remote[1] ]]; then
# No remote specified for this branch, skip fetch.
return 97
fi
# Default return code, which indicates Git fetch failure.
local fail_code=99
# Guard against all forms of password prompts. By setting the shell into
# MONITOR mode we can notice when a child process prompts for user input
# because it will be suspended. Since we are inside an async worker, we
# have no way of transmitting the password and the only option is to
# kill it. If we don't do it this way, the process will corrupt with the
# async worker.
setopt localtraps monitor
# Make sure local HUP trap is unset to allow for signal propagation when
# the async worker is flushed.
trap - HUP
trap '
# Unset trap to prevent infinite loop
trap - CHLD
if [[ $jobstates = suspended* ]]; then
# Set fail code to password prompt and kill the fetch.
fail_code=98
kill %%
fi
' CHLD
# Only fetch information for the current branch and avoid
# fetching tags or submodules to speed up the process.
command git -c gc.auto=0 fetch \
--quiet \
--no-tags \
--recurse-submodules=no \
$remote &>/dev/null &
wait $! || return $fail_code
unsetopt monitor
fi
return 0