-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.py
83 lines (62 loc) · 2.56 KB
/
core.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import sublime
import sublime_plugin
from . import GitTextCommand, GitWindowCommand
class GitCustomCommand(GitWindowCommand):
may_change_files = True
def run(self):
self.get_window().show_input_panel("Git command", "", self.on_input, None, None)
def on_input(self, command):
command = str(command) # avoiding unicode
if command.strip() == "":
self.panel("No git command provided")
return
import shlex
command_splitted = ["git"] + shlex.split(command)
print(command_splitted)
self.run_command(command_splitted)
class GitRawCommand(GitWindowCommand):
may_change_files = True
def run(self, **args):
self.command = str(args.get("command", ""))
show_in = str(args.get("show_in", "pane_below"))
if self.command.strip() == "":
self.panel("No git command provided")
return
import shlex
command_split = shlex.split(self.command)
if args.get("append_current_file", False) and self.active_file_name():
command_split.extend(("--", self.active_file_name()))
print(command_split)
self.may_change_files = bool(args.get("may_change_files", True))
if show_in == "pane_below":
self.run_command(command_split)
elif show_in == "quick_panel":
self.run_command(command_split, self.show_in_quick_panel)
elif show_in == "new_tab":
self.run_command(command_split, self.show_in_new_tab)
elif show_in == "suppress":
self.run_command(command_split, self.do_nothing)
view = self.active_view()
view.run_command("git_branch_status")
def show_in_quick_panel(self, result):
self.results = list(result.rstrip().split("\n"))
if len(self.results):
self.quick_panel(self.results, self.do_nothing, sublime.MONOSPACE_FONT)
else:
sublime.status_message("Nothing to show")
def do_nothing(self, picked):
return
def show_in_new_tab(self, result):
msg = self.window.new_file()
msg.set_scratch(True)
msg.set_name(self.command)
self._output_to_view(msg, result)
msg.sel().clear()
msg.sel().add(sublime.Region(0, 0))
# called by GitWindowCommand
class GitScratchOutputCommand(sublime_plugin.TextCommand):
def run(self, edit, output="", output_file=None, clear=False):
if clear:
region = sublime.Region(0, self.view.size())
self.view.erase(edit, region)
self.view.insert(edit, 0, output)