Created
September 7, 2016 22:01
-
-
Save soxofaan/843634bc2a6b5b453f76fd9795583b8b to your computer and use it in GitHub Desktop.
.xonshrc snippet with alias to reconnect SSH sockets (after reconnecting a screen session)
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
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(m.group(1)), m.group(2)) 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