From b509e8c35907c044a9e90f606d753fd1dfdbf25c Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Mon, 12 Aug 2013 14:40:06 -0400 Subject: [PATCH] added ability to add cheats via the command --- cheat | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cheat b/cheat index ad69b44..8b3c900 100755 --- a/cheat +++ b/cheat @@ -4,7 +4,8 @@ import sys # assemble a keyphrase out of all params passed to the script 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 if not os.path.isdir(cheat_dir): @@ -22,6 +23,16 @@ if keyphrase in ['', 'help', '--help', '-h']: print "\n".join(cheatsheets) 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 if keyphrase in cheatsheets: with open (cheat_dir + keyphrase, 'r') as cheatsheet: