Skip to content

Instantly share code, notes, and snippets.

@apathor
Created January 30, 2020 15:11
Show Gist options
  • Save apathor/6c47abff931b31ec2d979e403e7bed60 to your computer and use it in GitHub Desktop.
Save apathor/6c47abff931b31ec2d979e403e7bed60 to your computer and use it in GitHub Desktop.
# ; -*-shell-script-*-
# MFL's bash profile config for ssh and gpg agent
# shellcheck disable=SC1090
keyagents() {
# TODO
# add keys
# option to use gpg-agent for ssh
# ssh-agent
if type ssh-agent &>/dev/null; then
# source environment file if it exists
SSH_FILE="$HOME/.ssh-agent-info"
if [ -f "$SSH_FILE" ]; then
. "$SSH_FILE" &>/dev/null
fi
# start ssh-agent if it is not running
if [ -z "$SSH_AUTH_SOCK" ] \
|| ! kill -0 "$SSH_AGENT_PID" &>/dev/null; then
ssh-agent -s > "$SSH_FILE"
. "$SSH_FILE" &>/dev/null
# MAYBE trap 'kill $SSH_AGENT_PID' 0
fi
# update environment
export SSH_AUTH_SOCK
export SSH_AGENT_PID
fi
## gpg-agent
if type gpg-agent &>/dev/null; then
GPG_TTY=$(tty)
export GPG_TTY
# SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
# export GPG_TTY
# export SSH_AUTH_SOCK
fi
}
keyagents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment