Continuing to merge gbremer's work into master.

This commit is contained in:
Chris Lane 2013-08-15 18:03:58 -04:00
parent db4f793da2
commit 10cb62fee9
2 changed files with 12 additions and 12 deletions

22
cheat
View File

@ -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

View File

@ -8,5 +8,5 @@ try:
shutil.copytree('./.cheat', expanduser('~') + '/.cheat')
print "cheat has been installed successfully."
except IOError as e:
print >> sys.stderr, "This installer must be run as root."
print >> sys.stderr, e
sys.exit(1)