Skip to content

Instantly share code, notes, and snippets.

@rmcgibbo
Created August 27, 2012 00:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rmcgibbo/3484766 to your computer and use it in GitHub Desktop.
Execute command on remote server which is mounted via sshfs to open remote file on desktop
#!/usr/bin/env python
import os, sys
import subprocess
HOST_MOUNT_DIR = '\$HOME/ubuntu'
# get the ip of the host
host = os.environ['SSH_CLIENT'].split(' ')[0]
# get the path from $HOME to the file
file_path = os.path.relpath(os.path.abspath(sys.argv[1]),
os.path.expanduser('~'))
# get the path from to the file on the host filesystem
remote_path = os.path.join(HOST_MOUNT_DIR, file_path)
# we're going to use the default editor on the host
args = '/usr/bin/ssh %s "\$EDITOR %s"' % (host, remote_path)
print args
subprocess.Popen(args, shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment