-
Notifications
You must be signed in to change notification settings - Fork 3
/
ssh_agent.xsh
43 lines (33 loc) · 1.19 KB
/
ssh_agent.xsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Helper function to start SSH agent and add keys using ssh-add
"""
import builtins
from shutil import which
from repassh import ssh
__all__ = ()
def sshc(binary=which('ssh'), options={}):
def command(args, stdin=None, stdout=None, stderr=None):
"""Launch `repassh` with '[binary]' and the provided arguments
"""
opts = {}
opts.update(options)
opts.update({
"BINARY_SSH": binary,
"stdin": stdin,
"stdout": stdout,
"stderr": stderr
})
return ssh.main([''] + args, opts)
return command
builtins.aliases['ssh'] = sshc()
builtins.aliases['scp'] = sshc("scp")
builtins.aliases['sftp'] = sshc("sftp")
builtins.aliases['rsync'] = sshc("rsync", {"SSH_DEFAULT_OPTIONS": ""})
# set $GIT_SSH only if `repassh` can be used
repassh_command = builtins.__xonsh__.env.get("REPASSH_COMMAND", which('repassh'))
if 'GIT_SSH' not in ${...} and repassh_command:
$GIT_SSH = repassh_command
# set agent related environment variables
repassh_agentfile = ssh.get_agent_file()
if repassh_agentfile:
from xonsh.aliases import source_foreign_fn
source_foreign_fn('bash', [repassh_agentfile], sourcer="source")