added ability to add cheats via the command

This commit is contained in:
Benjamin Trent 2013-08-12 14:40:06 -04:00
parent 15fd673a51
commit b509e8c359
1 changed files with 12 additions and 1 deletions

13
cheat
View File

@ -4,7 +4,8 @@ import sys
# 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_dir = os.path.expanduser('~') + '/.cheat/' home = os.path.expanduser('~')
cheat_dir = home + '/.cheat/'
# verify that the ~/.cheat directory exists # verify that the ~/.cheat directory exists
if not os.path.isdir(cheat_dir): if not os.path.isdir(cheat_dir):
@ -22,6 +23,16 @@ if keyphrase in ['', 'help', '--help', '-h']:
print "\n".join(cheatsheets) print "\n".join(cheatsheets)
exit() exit()
if (len(sys.argv) > 1 and sys.argv[1] == 'add'):
if (len(sys.argv) > 2):
f = open(home + "/.cheat/" + sys.argv[2], 'a+')
f.write(' '.join(sys.argv[2:]))
f.close()
else:
print "Usage: cheat add [command with arguments]\n\n"
print "Example: cheat add curl -XPUT \"http://www.github.com\" #change request method for curl\n"
exit()
# print the cheatsheet if it exists # print the cheatsheet if it exists
if keyphrase in cheatsheets: if keyphrase in cheatsheets:
with open (cheat_dir + keyphrase, 'r') as cheatsheet: with open (cheat_dir + keyphrase, 'r') as cheatsheet: