Skip to content

Instantly share code, notes, and snippets.

@sandipb
Last active October 11, 2018 22:31
Show Gist options
  • Save sandipb/a28d3f0608b2a6f364e0c4e6da821839 to your computer and use it in GitHub Desktop.
Save sandipb/a28d3f0608b2a6f364e0c4e6da821839 to your computer and use it in GitHub Desktop.
Bashrc to keep a consistent tmux ssh-agent environment
SOCK="/tmp/ssh-agent-$USER-screen"
SOCKPTR="$(readlink -f $SOCK 2> /dev/null)"
if [[ -z $SOCKPTR ]] || [[ ! -S $SOCKPTR ]]
then
echo -e "\e[31m\e[1mNo valid current tmux ssh-agent link\e[0m"
if [[ -n $SSH_AUTH_SOCK ]] && [[ -S $SSH_AUTH_SOCK ]]
then
rm -f $SOCK
ln -nsf $SSH_AUTH_SOCK $SOCK
# export SSH_AUTH_SOCK=$SOCK
echo -e "\e[32m\e[1mSet tmux ssh-agent link to $SSH_AUTH_SOCK \e[0m"
fi
else
echo -e "\e[32m\e[1m Not changing tmux ssh-agent link. Already set to valid $SOCKPTR \e[0m"
fi
set-environment -g SSH_AUTH_SOCK /tmp/ssh-agent-$USER-screen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment