Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
.xonshrc snippet with alias to reconnect SSH sockets (after reconnecting a screen session)
def _reconnect_ssh_agent_socket(args, stdin=None):
import re
print("Updating ssh-agent socket environment. Current value: $SSH_AUTH_SOCK = %s" % $SSH_AUTH_SOCK)
# Use find to list candidate paths with timestamp (as float).
raw = $(find /tmp/ssh-* -user @$(whoami) -name 'agent*' -printf '%T@:%p;')
candidates = [(float(, for m in re.finditer('([0-9.]*):(.*?);', raw)]
# Take latest.
$SSH_AUTH_SOCK = max(candidates)[1]
print("Successfully updated. New value: $SSH_AUTH_SOCK = %s" % $SSH_AUTH_SOCK)
aliases['screenfix'] = _reconnect_ssh_agent_socket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.