Skip to content

Instantly share code, notes, and snippets.

@samuelcolvin
Last active October 21, 2016 16:28
Show Gist options
  • Save samuelcolvin/34f70766364a2f826de7723361e1b26c to your computer and use it in GitHub Desktop.
Save samuelcolvin/34f70766364a2f826de7723361e1b26c to your computer and use it in GitHub Desktop.
CLI interface to https://helpmanual.io/
#!/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)
  1. Download helpmanual.py and put it somewhere in the system PATH
  2. Create an alias to hm by editing .bashrc or eqivilent to add alias hm="helpmanual.py"
  3. Realise that that's ugly and slow as both "h" and "m" use the same finger, thing of a better alias.
@jaustin
Copy link

jaustin commented Oct 21, 2016

I'm going to use hio as the alias :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment