mirror of
https://github.com/cheat/cheat.git
synced 2024-11-25 07:21:36 +01:00
Continuing to merge gbremer's work into master.
This commit is contained in:
parent
db4f793da2
commit
10cb62fee9
22
cheat
22
cheat
@ -16,30 +16,30 @@ def cheat_files(cheat_directories):
|
||||
return cheats
|
||||
|
||||
# assemble a keyphrase out of all params passed to the script
|
||||
keyphrase = ' '.join(sys.argv[1:])
|
||||
keyphrase = ' '.join(sys.argv[1:])
|
||||
cheat_dirs = cheat_directories()
|
||||
|
||||
# verify that we have at least one cheat directory
|
||||
if not cheat_dirs:
|
||||
print >> sys.stderr, 'The ~/.cheat directory does not exist or the CHEATPATH variable is not set.'
|
||||
exit()
|
||||
print >> sys.stderr, 'The ~/.cheat directory does not exist or the CHEATPATH variable is not set.'
|
||||
exit()
|
||||
|
||||
# list the files in the ~/.cheat directory
|
||||
cheatsheets = cheat_files(cheat_dirs)
|
||||
|
||||
# print help if requested
|
||||
if keyphrase.lower() in ['', 'help', '--help', '-h']:
|
||||
print "Usage: cheat [keyphrase]\n"
|
||||
print "Available keyphrases:"
|
||||
max_command = max([ len(x) for x in cheatsheets.keys() ]) + 3
|
||||
print '\n'.join(sorted([ '%s [%s]' % (key.ljust(max_command), value) for key, value in cheatsheets.items() ]))
|
||||
exit()
|
||||
print "Usage: cheat [keyphrase]\n"
|
||||
print "Available keyphrases:"
|
||||
max_command = max([ len(x) for x in cheatsheets.keys() ]) + 3
|
||||
print '\n'.join(sorted([ '%s [%s]' % (key.ljust(max_command), value) for key, value in cheatsheets.items() ]))
|
||||
exit()
|
||||
|
||||
# print the cheatsheet if it exists
|
||||
if keyphrase in cheatsheets:
|
||||
with open (os.path.join(cheatsheets[keyphrase], keyphrase), 'r') as cheatsheet:
|
||||
print cheatsheet.read()
|
||||
with open (os.path.join(cheatsheets[keyphrase], keyphrase), 'r') as cheatsheet:
|
||||
print cheatsheet.read()
|
||||
|
||||
# if it does not, say so
|
||||
else:
|
||||
print 'No cheatsheet found for %s.' % keyphrase
|
||||
print 'No cheatsheet found for %s.' % keyphrase
|
||||
|
Loading…
Reference in New Issue
Block a user