-
-
Save comex/2faf21ebee93b0bd64841c30c7d28026 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
# SPDX-License-Identifier: CC0-1.0 | |
'''Wraps the ssh command, but quotes arguments so that they are passed 1:1 to | |
the remote command. | |
''' | |
import shlex, sys, os | |
args = sys.argv[1:][::-1] | |
out = ['ssh'] | |
while args and args[-1].startswith('-'): | |
arg = args.pop() | |
if arg == '--': | |
break | |
elif arg[-1] in 'BbcDEeFIiJLlmOopQRSWw': | |
out.append(arg) | |
out.append(args.pop()) | |
else: | |
out.append(arg) | |
out.append(args.pop()) # server | |
out.append(shlex.join(args[::-1])) # command | |
os.execvp(out[0], out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment