-
Notifications
You must be signed in to change notification settings - Fork 9
/
q_chain.py
34 lines (27 loc) · 1.11 KB
/
q_chain.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
import sublime
import sublime_plugin
#chain command and parse output to next command inputs
#example
#view.run_command("q_chain", {"chain": ["q_select_text", "q_send", "q_out_panel"]})
#view.run_command("q_chain", {"input": "til 10", "chain": ["q_send", "q_out_panel"]})
#view.run_command("q_chain", {"input": "test output", "chain": ["q_out_panel"]})
class QChainCommand(sublime_plugin.TextCommand):
def do(self, edit, input=None):
if input is not None:
return input
else:
return "start" #to start chain
def run(self, edit, input=None, chain=None):
output = self.do(edit, input)
if output is None:
print('break chain because output is none')
return
if chain is not None:
if len(chain) > 0:
print('\tchain ' + str(len(chain)) + ' command ' + chain[0] + '...')
self.view.run_command(chain[0], {"input": output, "chain": chain[1:]})
else:
print('finished chain')
else:
#no chain - just print output to console
print(output)