Last active
August 9, 2025 09:00
-
-
Save cumulus13/47f5d59bedf1ed1d737e3b38c6f35ffb to your computer and use it in GitHub Desktop.
Show and filter/search lexer
This file contains hidden or 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 python | |
| #author: Hadi Cahyadi (cumulus13@gmail.com) | |
| #license: MIT | |
| from pygments.lexers import get_all_lexers | |
| from rich.console import Console | |
| console = Console() | |
| def show_all_lexers(): | |
| lexers = sorted(get_all_lexers(), key=lambda l: l[0].lower()) | |
| def print_lexers(lexer_list): | |
| console.clear() | |
| console.print("Supported Pygments lexers:\n") | |
| if not lexer_list: | |
| console.print("[red]No lexers found with that filter[/]\n") | |
| else: | |
| for lexer in lexer_list: | |
| name = lexer[0] | |
| aliases = ", ".join(lexer[1]) | |
| exts = ", ".join(lexer[2]) | |
| console.print(f"[bold #00FFFF]{name}[/] | [bold #FFFF00]{aliases}[/] [bold #FF00EE]({exts})[/]") | |
| console.print("\n") | |
| print_lexers(lexers) | |
| while True: | |
| console.print("[white on blue]Type filter keyword (empty to show all), or q/x/exit/quit to exit[/]") | |
| q = input(": ").strip().lower() | |
| if q in {'q', 'x', 'exit', 'quit'}: | |
| break | |
| if q: | |
| filtered = [ | |
| lexer for lexer in lexers | |
| if q in lexer[0].lower() | |
| or any(q in alias for alias in lexer[1]) | |
| or any(q in ext for ext in lexer[2]) | |
| ] | |
| print_lexers(filtered) | |
| else: | |
| print_lexers(lexers) | |
| if __name__ == '__main__': | |
| show_all_lexers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment