Repository navigation
Expand file tree
/
Copy pathsearch.py
More file actions
57 lines (44 loc) · 1.48 KB
/
Copy pathsearch.py
File metadata and controls
57 lines (44 loc) · 1.48 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
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
import os
import sublime, sublime_plugin
view_prename = "search files for:"
class OpenFileSearchUnderSelectedCommand(sublime_plugin.TextCommand):
def run(self, edit):
if view_prename not in self.view.name():
return
sel = self.view.sel()[0]
if not sel.empty():
file_name = self.view.substr(sel)
else:
caret_pos = self.view.sel()[0].begin()
current_line = self.view.line(caret_pos)
left = current_line.begin()
right = current_line.end()
file_name = self.view.substr(sublime.Region(left, right))
print str(file_name )
file_name = file_name.strip()
if os.path.exists(file_name) and os.path.isfile(file_name):
self.view.window().open_file(file_name)
class EverythingSearchCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.show_input_panel("Search files:", "", self.on_done, None, None)
pass
def on_done(self, text):
view = self.window.new_file()
view.set_name(view_prename+text)
f=os.popen("es -n 100 -r " + text.encode('gbk'))
edit = view.begin_edit()
result = ""
count = 0
for l in f.readlines():
result += self.decodeText(l)
count += 1
result += "\n" + str(count) +" result"
view.insert(edit, 0, result)
view.end_edit(edit)
def decodeText(self, text):
result = ""
try:
result = text.decode('gbk')
except:
result = "Error Codec\n"
return result