Skip to content

Instantly share code, notes, and snippets.

@scgilardi
Created June 13, 2010 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scgilardi/436294 to your computer and use it in GitHub Desktop.
Save scgilardi/436294 to your computer and use it in GitHub Desktop.
# improved version of the code in Eivind Uggedal's comment at
# http://justinchouinard.com/blog/2010/04/10/fix-stale-ssh-environment-variables-in-gnu-screen-and-tmux/
function preexec() {
if [[ -n $TMUX ]]; then
TMUX_SOCK=$(echo $TMUX|cut -d , -f 1)
NEW_SSH_AUTH_SOCK=$(tmux -S $TMUX_SOCK showenv|grep ^SSH_AUTH_SOCK|cut -d = -f 2)
if [[ -n $NEW_SSH_AUTH_SOCK ]] && [[ -S $NEW_SSH_AUTH_SOCK ]]; then
SSH_AUTH_SOCK=$NEW_SSH_AUTH_SOCK
fi
fi
}
@drewr
Copy link

drewr commented Jun 13, 2010

Awesome! My psshes are so happy.

I like doing it elisp hook-style:

update_auth_sock () {
  if [[ -n $TMUX ]]; then
    TMUX_SOCK=$(echo $TMUX|cut -d , -f 1)
    NEW_SSH_AUTH_SOCK=$(tmux -S $TMUX_SOCK showenv|grep ^SSH_AUTH_SOCK|cut -d = -f 2)
    if [[ -n $NEW_SSH_AUTH_SOCK ]] && [[ -S $NEW_SSH_AUTH_SOCK ]]; then
      SSH_AUTH_SOCK=$NEW_SSH_AUTH_SOCK
    fi
  fi
}
preexec_functions+=update_auth_sock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment