Skip to content

Instantly share code, notes, and snippets.

@jijojv
Forked from karlseguin/gist:1876859
Last active January 16, 2017 03:08
Show Gist options
  • Save jijojv/8139217 to your computer and use it in GitHub Desktop.
Save jijojv/8139217 to your computer and use it in GitHub Desktop.
sublime scp to remote on save
#variation of http://urbangiraffe.com/2011/08/13/remote-editing-with-sublime-text-2/ that adds creating new folders remotely.
import sublime_plugin, os
class RemoteEdit(sublime_plugin.EventListener):
def on_post_save(self, view):
remote = { "/Users/jijo/work/project": ["/usr/bin/scp", None, "user@server", "~/project/", None] }
for dirname, target in remote.iteritems():
if view.file_name().startswith( dirname ):
if self.copy_file(view, target, dirname) == 256:
path = target[3] + os.path.dirname(target[4])
create_target = "ssh %s '[ -d %s || mkdir -p %s ]'" % (target[2], path, path)
if os.system( create_target ) == 0:
self.copy_file(view, target, dirname)
def copy_file(self, view, target, dirname):
target[1] = view.file_name()
target[4] = view.file_name()[len(dirname):]
print "%s %s %s:%s%s" % tuple(target)
return os.system( "%s %s %s:%s%s" % tuple(target) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment