Skip to content

Instantly share code, notes, and snippets.

@gfreezy
Created October 29, 2011 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfreezy/1324548 to your computer and use it in GitHub Desktop.
Save gfreezy/1324548 to your computer and use it in GitHub Desktop.
Sync plugin for Sumblime Text2 using a script 'sync' written by myself
[
{
"caption": "Sync: Pull",
"command": "sync_pull"
}
,{
"caption": "Sync: Push",
"command": "sync_push"
}
]
import sublime, sublime_plugin
import subprocess
import os
PYTHON = 'd:/cygwin/bin/python.exe'
class SyncWindowCommand(sublime_plugin.WindowCommand):
def _active_file_name(self):
view = self.active_view()
if view and view.file_name() and len(view.file_name()) > 0:
return view.file_name()
def active_view(self):
return self.window.active_view()
def get_working_dir(self):
file_name = self._active_file_name()
if file_name:
return os.path.dirname(file_name)
else:
return self.window.folders()[0]
def sync_root(directory):
while directory:
if os.path.exists(os.path.join(directory, 'sync')):
return directory
parent = os.path.realpath(os.path.join(directory, os.path.pardir))
if parent == directory:
# /.. == /
return False
directory = parent
return False
def convert_to_cygwin_path(path):
path = path.replace('\\', '/')
path = path.replace('D:', '/cygdrive/d')
return path
class SyncPullCommand(SyncWindowCommand):
def run(self):
root = sync_root(self.get_working_dir())
if root:
path = os.path.normpath(os.path.join(root, 'sync'))
path = convert_to_cygwin_path(path)
print repr(path)
s = subprocess.Popen('%s %s pull' % (PYTHON, path))
class SyncPushCommand(SyncWindowCommand):
def run(self):
root = sync_root(self.get_working_dir())
if root:
path = os.path.normpath(os.path.join(root, 'sync'))
path = convert_to_cygwin_path(path)
print repr(path)
s = subprocess.Popen('%s %s push' % (PYTHON, path))
@gfreezy
Copy link
Author

gfreezy commented Oct 29, 2011

Script sync can be found here.
git://gist.github.com/1324544.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment