mirror of
https://github.com/cheat/cheat.git
synced 2024-11-23 22:41:35 +01:00
Added a -S option to allow for keyword searching with ignored case
This commit is contained in:
parent
edd7b5e806
commit
def6aee807
@ -8,6 +8,7 @@ Usage:
|
|||||||
cheat <cheatsheet>
|
cheat <cheatsheet>
|
||||||
cheat -e <cheatsheet>
|
cheat -e <cheatsheet>
|
||||||
cheat -s <keyword>
|
cheat -s <keyword>
|
||||||
|
cheat -S <keyword>
|
||||||
cheat -l
|
cheat -l
|
||||||
cheat -d
|
cheat -d
|
||||||
cheat -v
|
cheat -v
|
||||||
@ -17,6 +18,7 @@ Options:
|
|||||||
-e --edit Edit cheatsheet
|
-e --edit Edit cheatsheet
|
||||||
-l --list List cheatsheets
|
-l --list List cheatsheets
|
||||||
-s --search Search cheatsheets for <keyword>
|
-s --search Search cheatsheets for <keyword>
|
||||||
|
-S --search-ignore-case Search cheatsheets for <keyword>, ignoring case
|
||||||
-v --version Print the version number
|
-v --version Print the version number
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
@ -58,7 +60,11 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# search among the cheatsheets
|
# search among the cheatsheets
|
||||||
elif options['--search']:
|
elif options['--search']:
|
||||||
print(colorize(sheets.search(options['<keyword>'])))
|
print(colorize(sheets.search(options['<keyword>'], True)))
|
||||||
|
|
||||||
|
# search among the cheatsheets, ignoring case
|
||||||
|
elif options['--search-ignore-case']:
|
||||||
|
print(colorize(sheets.search(options['<keyword>'], False)))
|
||||||
|
|
||||||
# print the cheatsheet
|
# print the cheatsheet
|
||||||
else:
|
else:
|
||||||
|
@ -76,15 +76,19 @@ def list():
|
|||||||
return sheet_list
|
return sheet_list
|
||||||
|
|
||||||
|
|
||||||
def search(term):
|
def search(term, match_case):
|
||||||
""" Searches all cheatsheets for the specified term """
|
""" Searches all cheatsheets for the specified term """
|
||||||
result = ''
|
result = ''
|
||||||
|
|
||||||
for cheatsheet in sorted(get().items()):
|
for cheatsheet in sorted(get().items()):
|
||||||
match = ''
|
match = ''
|
||||||
for line in open(cheatsheet[1]):
|
for line in open(cheatsheet[1]):
|
||||||
if term in line:
|
if match_case:
|
||||||
match += ' ' + line
|
if term in line:
|
||||||
|
match += ' ' + line
|
||||||
|
else:
|
||||||
|
if term.lower() in line.lower():
|
||||||
|
match += ' ' + line
|
||||||
|
|
||||||
if match != '':
|
if match != '':
|
||||||
result += cheatsheet[0] + ":\n" + match + "\n"
|
result += cheatsheet[0] + ":\n" + match + "\n"
|
||||||
|
BIN
man1/cheat.1.gz
BIN
man1/cheat.1.gz
Binary file not shown.
Loading…
Reference in New Issue
Block a user