]> git.wh0rd.org - home.git/blobdiff - .profile.d/keychain.sh
cros-board: update
[home.git] / .profile.d / keychain.sh
index 920035b3be2dd626f71400fadff971ca14ed96ba..c5ceb78f29c775263352e8c1fb955db75df96fee 100644 (file)
@@ -1,4 +1,16 @@
-if type -P keychain >/dev/null ; then
-       [ -e ~/.keychain/vapier-sh ] && source ~/.keychain/vapier-sh
-       [ -e ~/.keychain/vapier-sh-gpg ] && source ~/.keychain/vapier-sh-gpg
+# If an auth sock is already set & available, use it.
+# This way ssh agent forwarding still works.
+if type keychain >/dev/null 2>&1 ; then
+       if [ ! -S "${SSH_AUTH_SOCK}" ] ; then
+               : ${HOSTNAME:=$(hostname)}
+               [ -e ~/.keychain/${HOSTNAME}-sh ] && . ~/.keychain/${HOSTNAME}-sh
+       fi
+       if [ -z "${GPG_AGENT_INFO}" ] ; then
+               : ${HOSTNAME:=$(hostname)}
+               [ -e ~/.keychain/${HOSTNAME}-sh-gpg ] && . ~/.keychain/${HOSTNAME}-sh-gpg
+       fi
 fi
+
+# The agent might try to spawn pinentry on the tty it started
+# on instead of the tty gpg is now running on.
+export GPG_TTY="$(tty)"