Skip to content

Instantly share code, notes, and snippets.

@wynro
Last active January 14, 2017 00:26
Show Gist options
  • Save wynro/d8be5e4a2ebe581842d7a3b09ea44c79 to your computer and use it in GitHub Desktop.
Save wynro/d8be5e4a2ebe581842d7a3b09ea44c79 to your computer and use it in GitHub Desktop.
Gets you a random man. Remember, a man a day keeps the doctor away!
#!/usr/bin/env python
"""
Returns a random command's manpage
Author: Guillermo Robles
"""
import commands
import random
import os
def check_man(command):
"""
Returns True if the specified command has a manpage, False
otherwise
"""
output, _ = commands.getstatusoutput('/usr/bin/man ' + command)
return output == 0
# Get command list
_, coms = commands.getstatusoutput('/bin/bash -c "compgen -c"')
# Get a random one, repeat until we find one with manpage
man_exists = False
while not man_exists:
command = random.choice(coms.split('\n'))
man_exists = check_man(command)
# Show the manpage
os.system("/usr/bin/man " + command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment