public
Last active

Sublime 3 Text editor plugin for finding man page fast

  • Download Gist
Fast-Man.py
Python
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
 
import sublime, sublime_plugin
from subprocess import *
 
class man(sublime_plugin.TextCommand):
 
 
def run(self, edit):
#Set some global to work whit in
#other functions
global aedit
global window
global view
 
#Get the windows and the view
aedit=edit
window = self.view.window()
view = self.view
 
#if the selection is empty, ask for the page
if view.sel()[0].empty():
window.show_input_panel("Man search :", "", self.input_ret,None,None)
else:
#if search is not empty
word = view.substr(view.sel()[0])
self.man_search(aedit,word)
 
 
def input_ret(self,text):
#if an text is set, search it
if text:
self.man_search(aedit,text)
 
 
def man_search(self,edit,to_search):
text = "{}".format(to_search)
#Open the man panel
man_panel = window.get_output_panel("man")
 
#Wait that the panel is ready
while man_panel.is_loading():
pass
 
#print the search in console
print("searching in man: {}".format(text))
 
#Command to send
man_command=["man","-P","cat","-7","-a", text]
 
#Open the pipe and redirect stdout to the pipe
pipe = Popen(man_command,stdout=PIPE,stderr=STDOUT)
(in_pipe,out_pipe) = pipe.communicate()
 
#insert text in the man panel
man_panel.insert(edit, 0, in_pipe.decode("utf-8"))
 
#Show the panel
window.run_command("show_panel",{"panel":"output.man"})

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.