2013-07-31 04:48:07 +02:00
|
|
|
#!/usr/bin/env python
|
2013-08-10 23:08:17 +02:00
|
|
|
from os.path import expanduser
|
|
|
|
import imp
|
2013-07-31 04:48:07 +02:00
|
|
|
import sys
|
|
|
|
|
2013-07-31 05:25:36 +02:00
|
|
|
# assemble a keyphrase out of all params passed to the script
|
|
|
|
keyphrase = ' '.join(sys.argv[1:])
|
|
|
|
|
2013-08-10 23:08:17 +02:00
|
|
|
# load the dictionary of cheatsheets
|
|
|
|
config = imp.load_source('config', expanduser('~') + '/.cheat');
|
2013-08-10 05:46:34 +02:00
|
|
|
|
2013-07-31 05:33:31 +02:00
|
|
|
# print help if requested
|
2013-07-31 05:57:04 +02:00
|
|
|
if keyphrase in ['', 'help', '--help', '-h']:
|
2013-08-10 23:08:17 +02:00
|
|
|
cheatsheets_sorted = config.cheatsheets.keys()
|
2013-08-10 04:24:12 +02:00
|
|
|
cheatsheets_sorted.sort()
|
|
|
|
|
|
|
|
print "Usage: cheat [keyphrase]\n"
|
|
|
|
print "Available keyphrases:"
|
|
|
|
print "\n".join(cheatsheets_sorted)
|
2013-07-31 05:25:36 +02:00
|
|
|
exit()
|
|
|
|
|
2013-07-31 05:33:31 +02:00
|
|
|
# print the cheatsheet if it exists
|
2013-08-10 23:08:17 +02:00
|
|
|
print config.cheatsheets[keyphrase] if keyphrase in config.cheatsheets.keys() else 'No cheatsheet found.'
|