From def6aee80762ff7e843d6e0efe8c0f7a945bd47a Mon Sep 17 00:00:00 2001 From: Tyler Culp Date: Thu, 22 Jun 2017 14:54:52 -0400 Subject: [PATCH] Added a -S option to allow for keyword searching with ignored case --- bin/cheat | 8 +++++++- cheat/sheets.py | 10 +++++++--- man1/cheat.1.gz | Bin 975 -> 992 bytes 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/cheat b/bin/cheat index a14e3a9..c009906 100755 --- a/bin/cheat +++ b/bin/cheat @@ -8,6 +8,7 @@ Usage: cheat cheat -e cheat -s + cheat -S cheat -l cheat -d cheat -v @@ -17,6 +18,7 @@ Options: -e --edit Edit cheatsheet -l --list List cheatsheets -s --search Search cheatsheets for + -S --search-ignore-case Search cheatsheets for , ignoring case -v --version Print the version number Examples: @@ -58,7 +60,11 @@ if __name__ == '__main__': # search among the cheatsheets elif options['--search']: - print(colorize(sheets.search(options['']))) + print(colorize(sheets.search(options[''], True))) + + # search among the cheatsheets, ignoring case + elif options['--search-ignore-case']: + print(colorize(sheets.search(options[''], False))) # print the cheatsheet else: diff --git a/cheat/sheets.py b/cheat/sheets.py index 1a0b28e..07c509e 100644 --- a/cheat/sheets.py +++ b/cheat/sheets.py @@ -76,15 +76,19 @@ def list(): return sheet_list -def search(term): +def search(term, match_case): """ Searches all cheatsheets for the specified term """ result = '' for cheatsheet in sorted(get().items()): match = '' for line in open(cheatsheet[1]): - if term in line: - match += ' ' + line + if match_case: + if term in line: + match += ' ' + line + else: + if term.lower() in line.lower(): + match += ' ' + line if match != '': result += cheatsheet[0] + ":\n" + match + "\n" diff --git a/man1/cheat.1.gz b/man1/cheat.1.gz index 65bc32f34dc82e05efacd90a976d58dc35c0da7f..acc6c18dcacac5c4f5d30ad2bbe54c1211514364 100644 GIT binary patch literal 992 zcmV<610Vb!iwFSC5lmSC1C>=>Z`(E$eb=wJFb1pzY`NLcJp>pqC-rKhNo+(eiXh1Y zEnQheX;LGp#QOI;q-5D?_p%4W5_!MQx#wP`Pb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