Created
October 29, 2011 14:56
-
-
Save gfreezy/1324548 to your computer and use it in GitHub Desktop.
Sync plugin for Sumblime Text2 using a script 'sync' written by myself
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
[ | |
{ | |
"caption": "Sync: Pull", | |
"command": "sync_pull" | |
} | |
,{ | |
"caption": "Sync: Push", | |
"command": "sync_push" | |
} | |
] |
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
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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script
sync
can be found here.git://gist.github.com/1324544.git