From 34f3eafb1a905c88f100dbe7f91721004be10447 Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Sat, 14 Sep 2013 09:36:15 -0400 Subject: [PATCH] Created the -l option to list cheatsheets. I believe this is goign to be helpful to expose to scripts that are attempting to implement autocomplete. --- cheat | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cheat b/cheat index 845fc8e..397a306 100755 --- a/cheat +++ b/cheat @@ -108,12 +108,16 @@ def help(cheatsheets): Available keyphrases: ''').strip() - 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 list_cheatsheets(cheatsheets) exit() +def list_cheatsheets(cheatsheets): + max_command = max([len(x) for x in cheatsheets.keys()]) + 3 + return ('\n'.join(sorted(['%s [%s]' % (key.ljust(max_command), value) + for key, value in cheatsheets.items()]))) + + def pretty_print(filename): "Applies syntax highlighting to a cheatsheet and writes it to stdout" try: @@ -177,6 +181,11 @@ def main(): print("\n".join(cheat_directories())) exit() + # list cheatsheets and exit + if option in ['-l', '--list']: + print list_cheatsheets(cheatsheets) + exit() + # print the cheatsheet if it exists if keyphrase in cheatsheets: filename = os.path.join(cheatsheets[keyphrase], keyphrase)