Permalink
Browse files

Fixed #11

  • Loading branch information...
1 parent 0ac189e commit 400f812d404e947159b67f08a4eced9d6af078ce Vishal Rana committed Mar 22, 2013
Showing with 38 additions and 17 deletions.
  1. +3 −0 Context.sublime-menu
  2. +3 −0 Default.sublime-commands
  3. +9 −6 README.md
  4. +22 −11 history.py
  5. +1 −0 package-metadata.json
View
@@ -3,6 +3,9 @@
}, {
"caption": "Local History",
"children": [{
+ "caption": "Browse",
+ "command": "history_browse"
+ }, {
"caption": "Open",
"command": "history_open"
}, {
View
@@ -1,4 +1,7 @@
[{
+ "caption": "Local History: Browse",
+ "command": "history_browse"
+}, {
"caption": "Local History: Open",
"command": "history_open"
}, {
View
@@ -1,5 +1,5 @@
# Local History
-A Sublime Text 2 plugin for maintaining local history of files
+A Sublime Text 2/3 plugin for maintaining local history of files
##Benefits
@@ -30,14 +30,17 @@ The "Packages" directory location:
`%APPDATA%/Sublime Text 2/Packages/`
## Usage
-![Settings](http://i.imgur.com/vD3QT.png)
-
-![Open | Compare | Replace | Incremental Diff](http://i.imgur.com/qeoGl.png)
-
-![Open | Compare | Replace | Incremental Diff](http://i.imgur.com/ADMgy.png)
+![Open | Compare | Replace | Incremental Diff](http://i.imgur.com/jNMrT8Q.png)
![Delete All](http://i.imgur.com/nUlx8.png)
+### Settings
+```js
+{
+ "history_limit": 100,
+ "file_size_limit": 262144 // 256 KiB
+}
+```
## Caveats
View
@@ -1,5 +1,3 @@
-import sublime
-import sublime_plugin
import sys
import os
import glob
@@ -9,12 +7,18 @@
import filecmp
import shutil
from threading import Thread
+import subprocess
+import sublime
+import sublime_plugin
#==============#
# Settings #
#==============#
PY2 = sys.version_info < (3, 0)
-HISTORY_PATH = os.path.join(os.path.abspath(os.path.expanduser("~")), ".sublime", "history")
+HISTORY_ROOT = os.path.join(os.path.abspath(os.path.expanduser("~")), ".sublime", "history")
+settings = sublime.load_settings("LocalHistory.sublime-settings")
+FILE_SIZE_LIMIT = settings.get("file_size_limit")
+HISTORY_LIMIT = settings.get("history_limit")
#==============#
# Messages #
@@ -33,16 +37,12 @@ def get_file_dir(file_path):
file_dir = file_dir.replace(":", "", 1)
else:
file_dir = file_dir[1:] # Trim the root
- return os.path.join(HISTORY_PATH, file_dir)
+ return os.path.join(HISTORY_ROOT, file_dir)
class HistorySave(sublime_plugin.EventListener):
def on_post_save(self, view):
- settings = sublime.load_settings("LocalHistory.sublime-settings")
- FILE_SIZE_LIMIT = settings.get("file_size_limit")
- HISTORY_LIMIT = settings.get("history_limit")
-
def run(file_path):
if PY2:
file_path = file_path.encode("utf-8")
@@ -70,8 +70,7 @@ def run(file_path):
return
# Store history
- shutil.copyfile(file_path, os.path.join(history_dir, "{0}.{1}".
- format(dt.now().strftime("%Y-%m-%d_%H.%M.%S"), file_name)))
+ shutil.copyfile(file_path, os.path.join(history_dir, "{0}.{1}".format(dt.now().strftime("%Y-%m-%d_%H.%M.%S"), file_name)))
# Remove old files
for file in history_files[HISTORY_LIMIT - 1:]: # -1 as we just added a new file
@@ -82,6 +81,18 @@ def run(file_path):
t.start()
+class HistoryBrowse(sublime_plugin.TextCommand):
+
+ def run(self, edit):
+ system = platform.system()
+ if system == "Darwin":
+ subprocess.call(["open", get_file_dir(self.view.file_name())])
+ elif system == "Linux":
+ subprocess.call(["xdg-open", get_file_dir(self.view.file_name())])
+ elif system == "Windows":
+ subprocess.call(["explorer", get_file_dir(self.view.file_name())])
+
+
class HistoryOpen(sublime_plugin.TextCommand):
def run(self, edit):
@@ -252,5 +263,5 @@ def run(self, edit, **kwargs):
class HistoryDeleteAll(sublime_plugin.TextCommand):
def run(self, edit):
- shutil.rmtree(HISTORY_PATH)
+ shutil.rmtree(HISTORY_ROOT)
sublime.status_message(HISTORY_DELETED_MSG)
View
@@ -0,0 +1 @@
+{"url": "http://vishalrana.com/local-history/", "version": "2013.03.01.17.57.28", "description": "A Sublime Text 2/3 plugin for maintaining local history of files. [backup | open | compare | replace | incremental diff]"}

0 comments on commit 400f812

Please sign in to comment.