Last active
January 14, 2017 00:26
-
-
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!
This file contains 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 | |
""" | |
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