Remove double ssh agent usage, add gpg-agent.

This commit is contained in:
2024-10-04 15:29:00 -04:00
parent 0d268ae40e
commit 319f08d2a7
+14 -24
View File
@@ -135,29 +135,19 @@ if [ -f $HOME/.exports ]; then
source $HOME/.exports source $HOME/.exports
fi fi
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. # Set GPG TTY
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh export GPG_TTY=$(tty)
# Refresh gpg-agent tty in case user switches into an X session
# ssh agent set up gpg-connect-agent updatestartuptty /bye >/dev/null
# Requires your user to have write privileges in .ssh. # Set SSH to use gpg-agent
env=~/.ssh/agent.env unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; } export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
agent_start () { # Start the gpg-agent if not already running
(umask 077; ssh-agent >| "$env") if ! pgrep -x -u "${USER}" gpg-agent >/dev/null 2>&1; then
. "$env" >| /dev/null ; } gpg-connect-agent /bye >/dev/null 2>&1
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi fi
unset env # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh