t=${TMPDIR:-/tmp}/home-$LOGNAME
h=$HOME/tmp
if [[ ! -e $t ]] {
- mkdir -m 700 $t > /dev/null 2>&1
+ mkdir -m 700 $t >/dev/null 2>&1
# TODO: check if dir exists after mkdir
}
# allow opaque entries to override link creation
if [[ ! -e $h ]] {
- ln -sf $t $h > /dev/null 2>&1
+ ln -sf $t $h >/dev/null 2>&1
}
unset t h
## ssh agents
# NOTE: preferred order of agents to check: okcagent, gnupg, openssh
# first block takes care of okcagent and openssh, second gnupg
- print -nP "%F{blue}>>>%f SSH: %F{green}"
+ [[ -o interactive ]] && print -nP "%F{blue}>>>%f SSH: %F{green}"
if [[ ! -v SSH_AUTH_SOCK && ( -v commands[okc-ssh-agent] ||
( -v commands[ssh-agent] && ! -v commands[gpg] ) ) ]] {
okc=${commands[okc-ssh-agent]:+okc-}
IFS=$'\0' read -r sock pid <$agentfile
}
if [[ -S $sock && $pid > 0 ]] && kill -0 $pid; then
- echo "Reusing agent pid $pid"
+ [[ -o interactive ]] && echo "Reusing agent pid $pid"
export SSH_AUTH_SOCK=$sock
export SSH_AGENT_PID=$pid
else
# TODO: ensure ssh-agent path looks legit
# to avoid unsafe eval?
- eval `${okc}ssh-agent`
+ # NOTE: no way around doing redirection like this I think
+ e=${okc}ssh-agent
+ if [[ -o interactive ]] {
+ eval `$e`
+ } else {
+ eval `$e` >/dev/null 2>&1
+ }
echo -n $SSH_AUTH_SOCK$'\0'$SSH_AGENT_PID >!$agentfile
fi
unset okc agentfile sock pid
export GPG_TTY=$(tty)
export PINENTRY_USER_DATA=USE_TTY=$((!${+DISPLAY}))
gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null 2>&1
- gpg-connect-agent /subst /serverpid \
+ [[ -o interactive ]] && gpg-connect-agent /subst /serverpid \
'/echo GPG agent pid ${get serverpid}' /bye
[[ ! -v SSH_AUTH_SOCK ]] && \
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
} else {
- echo "Pre-existing or remote agent"
+ [[ -o interactive ]] && echo "Pre-existing or remote agent"
}
## gpg ssh forwarding