cheat-fork-echo/cheat

24 lines
686 B
Text
Raw Normal View History

2013-07-31 04:48:07 +02:00
#!/usr/bin/env python
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:])
# load the dictionary of cheatsheets
config = imp.load_source('config', expanduser('~') + '/.cheat');
2013-08-10 05:46:34 +02:00
# print help if requested
2013-07-31 05:57:04 +02:00
if keyphrase in ['', 'help', '--help', '-h']:
cheatsheets_sorted = config.cheatsheets.keys()
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()
# print the cheatsheet if it exists
print config.cheatsheets[keyphrase] if keyphrase in config.cheatsheets.keys() else 'No cheatsheet found.'