mirror of https://github.com/cheat/cheat.git
33 lines
835 B
Python
Executable File
33 lines
835 B
Python
Executable File
#!/usr/bin/env python
|
|
import os
|
|
import sys
|
|
|
|
# assemble a keyphrase out of all params passed to the script
|
|
keyphrase = ' '.join(sys.argv[1:])
|
|
cheat_dir = os.path.expanduser('~') + '/.cheat/'
|
|
|
|
# verify that the ~/.cheat directory exists
|
|
if not os.path.isdir(cheat_dir):
|
|
print >> sys.stderr, 'The ~/.cheat directory does not exist.'
|
|
exit()
|
|
|
|
# list the files in the ~/.cheat directory
|
|
cheatsheets = os.listdir(cheat_dir)
|
|
cheatsheets.sort()
|
|
|
|
# print help if requested
|
|
if keyphrase in ['', 'help', '--help', '-h']:
|
|
print "Usage: cheat [keyphrase]\n"
|
|
print "Available keyphrases:"
|
|
print "\n".join(cheatsheets)
|
|
exit()
|
|
|
|
# print the cheatsheet if it exists
|
|
if keyphrase in cheatsheets:
|
|
with open (cheat_dir + keyphrase, 'r') as cheatsheet:
|
|
print cheatsheet.read()
|
|
|
|
# if it does not, say so
|
|
else:
|
|
print 'No cheatsheet found.'
|