Created
November 27, 2013 00:36
-
-
Save nhoffman/7668848 to your computer and use it in GitHub Desktop.
ssh-refresh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_ssh_sock(){ | |
sock=$(find /tmp/ssh-* -user $USER -name "agent.*" 2> /dev/null | head -1) | |
if [[ -z $sock ]]; then | |
eval $(ssh-agent -s) | |
fi | |
find /tmp/ssh-* -user $USER -name "agent.*" 2> /dev/null | head -1 | |
} | |
function ssh-refresh() { | |
echo shell: SSH_AUTH_SOCK=$SSH_AUTH_SOCK | |
export SSH_AUTH_SOCK=$(get_ssh_sock) | |
echo shell: SSH_AUTH_SOCK=$SSH_AUTH_SOCK | |
if [[ -n $TMUX ]]; then | |
TMUX_SOCK=$(echo $TMUX|cut -d , -f 1) | |
echo -n 'tmux: '; tmux -S $TMUX_SOCK showenv | grep SSH_AUTH_SOCK | |
tmux -S $TMUX_SOCK setenv SSH_AUTH_SOCK $SSH_AUTH_SOCK | |
echo -n 'tmux: '; tmux -S $TMUX_SOCK showenv | grep SSH_AUTH_SOCK | |
fi | |
local NEW_DISPLAY=$(tmux showenv | grep -E "^DISPLAY" | cut -d= -f2) | |
if [[ -n $NEW_DISPLAY ]]; then | |
print "Display: $NEW_DISPLAY" | |
export DISPLAY=$NEW_DISPLAY | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment