- Download
helpmanual.py
and put it somewhere in the systemPATH
- Create an alias to
hm
by editing.bashrc
or eqivilent to addalias hm="helpmanual.py"
- Realise that that's ugly and slow as both "h" and "m" use the same finger, thing of a better alias.
Last active
October 21, 2016 16:28
-
-
Save samuelcolvin/34f70766364a2f826de7723361e1b26c to your computer and use it in GitHub Desktop.
CLI interface to https://helpmanual.io/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Open helpmanual.io man pages | |
Samuel Colvin 2016 | |
""" | |
import json | |
import platform | |
import subprocess | |
import shlex | |
import sys | |
try: | |
from httplib import HTTPSConnection | |
except ImportError: | |
from http.client import HTTPSConnection | |
def get_browser_opener(): | |
system = platform.system() | |
if system == 'Linux': | |
return 'gnome-open' # what about linux without gnome? | |
elif system == 'Windows': | |
return 'start chrome' # random guess, I don't much care | |
else: | |
return 'open' # osx at least | |
def helpmanual(): | |
args = ' '.join(sys.argv[1:]) | |
if not args: | |
return 'No arguments supplied, usage: "{} <search string>"'.format(sys.argv[0]) | |
c = HTTPSConnection('search.helpmanual.io') | |
c.request('GET', '/' + args) | |
r = c.getresponse() | |
if not r.status == 200: | |
return 'Connection error {}: {}'.format(r.status, r.reason) | |
results = json.loads(r.read().decode('utf8')) | |
if not results: | |
return 'no results found' | |
page_url = 'https://helpmanual.io{uri}'.format(**results[0]) | |
print('opening "{}"'.format(page_url)) | |
command = '{} {}'.format(get_browser_opener(), page_url) | |
p = subprocess.Popen(shlex.split(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE) | |
p.wait() | |
assert p.returncode == 0 | |
if __name__ == '__main__': | |
error_msg = helpmanual() | |
if error_msg: | |
print(error_msg) | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm going to use hio as the alias :)