forked from silvo38/SublimeCommandOnSave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandOnSave.py
More file actions
30 lines (26 loc) · 1.2 KB
/
Copy pathCommandOnSave.py
File metadata and controls
30 lines (26 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sublime
import sublime_plugin
import subprocess
import re
import os
class CommandOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
settings = sublime.load_settings('CommandOnSave.sublime-settings').get('commands')
touchfile = sublime.load_settings('CommandOnSave.sublime-settings').get('touchfile') or "inhibit-cos"
file = view.file_name()
basename = os.path.basename(file)
dirname = os.path.dirname(file)
if not (
settings == None
or os.path.isfile(os.path.join(dirname,touchfile))
or os.path.isfile(os.path.expanduser("~/"+touchfile))
):
for path in settings.keys():
commands = settings.get(path)
if re.search(path, file) is not None and len(commands) > 0:
for command in commands:
command = command.format(filename=file,basename=basename,dirname=dirname)
print("Command on Save: " + command )
p = subprocess.Popen([command], shell=True, stdout=subprocess.PIPE)
out, err = p.communicate()
print (out.decode('utf-8'))