Skip to content

Instantly share code, notes, and snippets.

@comex
Last active July 14, 2023 21:36
Show Gist options
  • Save comex/2faf21ebee93b0bd64841c30c7d28026 to your computer and use it in GitHub Desktop.
Save comex/2faf21ebee93b0bd64841c30c7d28026 to your computer and use it in GitHub Desktop.
#!/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