mirror of https://github.com/cheat/cheat.git
24 lines
686 B
Python
Executable File
24 lines
686 B
Python
Executable File
#!/usr/bin/env python
|
|
from os.path import expanduser
|
|
import imp
|
|
import sys
|
|
|
|
# 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');
|
|
|
|
# print help if requested
|
|
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)
|
|
exit()
|
|
|
|
# print the cheatsheet if it exists
|
|
print config.cheatsheets[keyphrase] if keyphrase in config.cheatsheets.keys() else 'No cheatsheet found.'
|