mirror of
https://github.com/Erreur32/cheat.git
synced 2024-12-22 21:52:12 +01:00
8dda6a9241
Created cheatsheets package to store the default sheets.
33 lines
896 B
Python
Executable file
33 lines
896 B
Python
Executable file
#!/usr/bin/env python
|
|
import os
|
|
import sys
|
|
from cheatsheets import cheat_dir
|
|
|
|
# assemble a keyphrase out of all params passed to the script
|
|
keyphrase = ' '.join(sys.argv[1:])
|
|
|
|
# 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 = [f for f in os.listdir(cheat_dir) if '.' not in f]
|
|
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:
|
|
cheatsheet_filename = os.path.join(cheat_dir, keyphrase)
|
|
with open(cheatsheet_filename, 'r') as cheatsheet:
|
|
print cheatsheet.read()
|
|
|
|
# if it does not, say so
|
|
else:
|
|
print 'No cheatsheet found.'
|