Create a gist now

Instantly share code, notes, and snippets.

Sublime 3 Text editor plugin for finding man page fast
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
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)
#if search is not empty
word = view.substr(view.sel()[0])
def input_ret(self,text):
#if an text is set, search it
if 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():
#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.run_command("simple_insert", {"content": in_pipe.decode("utf-8")})
#Show the panel
class SimpleInsertCommand(sublime_plugin.TextCommand):
def run(self, edit, content):
self.view.insert(edit, 0, content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment