Skip to content

Instantly share code, notes, and snippets.

@grische
Last active March 9, 2024 18:28
Show Gist options
  • Save grische/852d856eb80e2992ba8400ebcf6f5488 to your computer and use it in GitHub Desktop.
Save grische/852d856eb80e2992ba8400ebcf6f5488 to your computer and use it in GitHub Desktop.
if [ -z "$XDG_RUNTIME_DIR" ]; then
export XDG_RUNTIME_DIR=$HOME/.xdg
mkdir -m700 -p ${XDG_RUNTIME_DIR}
fi
# Check if we found an environment file already
if [[ ! "$SSH_AUTH_SOCK" ]]; then
if [ -e "$XDG_RUNTIME_DIR/ssh-agent.env" ]; then
source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
# Check if current ssh-agent is still running
if ! kill -0 "$SSH_AGENT_PID" > /dev/null; then
ssh-agent -t 15h > "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
else
ssh-agent -t 15h > "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
source "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment