Created
August 11, 2022 14:39
-
-
Save phwelo/9846256c2ced628896eb412745dbecde to your computer and use it in GitHub Desktop.
Highlight - Simple grep tool that highlights instead of displaying only results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from colorama import init, Fore, Back, Style | |
import sys | |
import argparse | |
init(autoreset=True) | |
what_color = Fore.BLACK + Back.WHITE | |
parser = argparse.ArgumentParser(exit_on_error=False) | |
parser.add_argument('search_string') | |
args = parser.parse_args() | |
for line in sys.stdin: | |
if args.search_string in str(line): | |
search_string = args.search_string | |
highlight_string = what_color + search_string + Style.RESET_ALL | |
splitted = line.split(search_string) | |
unsplit = highlight_string.join(splitted) | |
print(unsplit) | |
else: | |
print(line)% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment