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
|
return cheats
|
||||||
|
|
||||||
# assemble a keyphrase out of all params passed to the script
|
# 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()
|
cheat_dirs = cheat_directories()
|
||||||
|
|
||||||
# verify that we have at least one cheat directory
|
# verify that we have at least one cheat directory
|
||||||
if not cheat_dirs:
|
if not cheat_dirs:
|
||||||
print >> sys.stderr, 'The ~/.cheat directory does not exist or the CHEATPATH variable is not set.'
|
print >> sys.stderr, 'The ~/.cheat directory does not exist or the CHEATPATH variable is not set.'
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# list the files in the ~/.cheat directory
|
# list the files in the ~/.cheat directory
|
||||||
cheatsheets = cheat_files(cheat_dirs)
|
cheatsheets = cheat_files(cheat_dirs)
|
||||||
|
|
||||||
# print help if requested
|
# print help if requested
|
||||||
if keyphrase.lower() in ['', 'help', '--help', '-h']:
|
if keyphrase.lower() in ['', 'help', '--help', '-h']:
|
||||||
print "Usage: cheat [keyphrase]\n"
|
print "Usage: cheat [keyphrase]\n"
|
||||||
print "Available keyphrases:"
|
print "Available keyphrases:"
|
||||||
max_command = max([ len(x) for x in cheatsheets.keys() ]) + 3
|
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() ]))
|
print '\n'.join(sorted([ '%s [%s]' % (key.ljust(max_command), value) for key, value in cheatsheets.items() ]))
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# print the cheatsheet if it exists
|
# print the cheatsheet if it exists
|
||||||
if keyphrase in cheatsheets:
|
if keyphrase in cheatsheets:
|
||||||
with open (os.path.join(cheatsheets[keyphrase], keyphrase), 'r') as cheatsheet:
|
with open (os.path.join(cheatsheets[keyphrase], keyphrase), 'r') as cheatsheet:
|
||||||
print cheatsheet.read()
|
print cheatsheet.read()
|
||||||
|
|
||||||
# if it does not, say so
|
# if it does not, say so
|
||||||
else:
|
else:
|
||||||
print 'No cheatsheet found for %s.' % keyphrase
|
print 'No cheatsheet found for %s.' % keyphrase
|
||||||
|
2
install
2
install
@ -8,5 +8,5 @@ try:
|
|||||||
shutil.copytree('./.cheat', expanduser('~') + '/.cheat')
|
shutil.copytree('./.cheat', expanduser('~') + '/.cheat')
|
||||||
print "cheat has been installed successfully."
|
print "cheat has been installed successfully."
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
print >> sys.stderr, "This installer must be run as root."
|
print >> sys.stderr, e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user