From 9aebfa4cb355b67c4c1deb4475de9e020bb103d6 Mon Sep 17 00:00:00 2001 From: zhaozigu Date: Thu, 12 Mar 2026 10:28:20 +0800 Subject: [PATCH 1/2] [cli] Add fuzzy search filter to list and list-installed commands Add -s/--search option that filters games by title or app name using case-insensitive token matching. --- legendary/cli.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/legendary/cli.py b/legendary/cli.py index 9d8430d..c2b5bb2 100644 --- a/legendary/cli.py +++ b/legendary/cli.py @@ -70,6 +70,13 @@ class LegendaryCLI: else: print(json.dumps(data)) + @staticmethod + def _match_search(query, *fields): + """Return True if all whitespace-separated tokens in query appear in any of the given fields (case-insensitive).""" + tokens = query.lower().split() + combined = ' '.join(f.lower() for f in fields if f) + return all(t in combined for t in tokens) + def auth(self, args): if args.auth_delete: self.core.lgd.invalidate_userdata() @@ -216,6 +223,9 @@ class LegendaryCLI: dlc_list[citem_id].extend(na_dlcs[citem_id]) dlc_list[citem_id] = sorted(dlc_list[citem_id], key=lambda d: d.app_title.lower()) + if args.search: + games = [g for g in games if self._match_search(args.search, g.app_title, g.app_name)] + if args.csv or args.tsv: writer = csv.writer(stdout, dialect='excel-tab' if args.tsv else 'excel', lineterminator='\n') writer.writerow(['App name', 'App title', 'Version', 'Is DLC']) @@ -280,6 +290,9 @@ class LegendaryCLI: games = sorted(self.core.get_installed_list(include_dlc=True), key=lambda x: x.title.lower()) + if args.search: + games = [g for g in games if self._match_search(args.search, g.title, g.app_name)] + versions = dict() for game in games: try: @@ -2873,6 +2886,8 @@ def main(): list_parser.add_argument('--json', dest='json', action='store_true', help='List games in JSON format') list_parser.add_argument('--force-refresh', dest='force_refresh', action='store_true', help='Force a refresh of all game metadata') + list_parser.add_argument('-s', '--search', dest='search', action='store', metavar='', + help='Filter results by title or app name (fuzzy, case-insensitive)') list_installed_parser.add_argument('--check-updates', dest='check_updates', action='store_true', help='Check for updates for installed games') @@ -2884,6 +2899,8 @@ def main(): help='List games in JSON format') list_installed_parser.add_argument('--show-dirs', dest='include_dir', action='store_true', help='Print installation directory in output') + list_installed_parser.add_argument('-s', '--search', dest='search', action='store', metavar='', + help='Filter results by title or app name (fuzzy, case-insensitive)') list_files_parser.add_argument('--force-download', dest='force_download', action='store_true', help='Always download instead of using on-disk manifest') From 15fa16a135725abc5d1c60fb3398b77f5bd587d0 Mon Sep 17 00:00:00 2001 From: zhaozigu Date: Thu, 12 Mar 2026 10:33:49 +0800 Subject: [PATCH 2/2] Update README --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 32fa4af..e9283d1 100644 --- a/README.md +++ b/README.md @@ -548,7 +548,8 @@ optional arguments: --tsv List games in TSV format --json List games in JSON format --force-refresh Force a refresh of all game metadata - + -s , --search + Filter results by title or app name (fuzzy, case-insensitive) Command: list-files usage: legendary list-files [-h] [--force-download] [--platform ] @@ -584,7 +585,8 @@ optional arguments: --tsv List games in TSV format --json List games in JSON format --show-dirs Print installation directory in output - + -s , --search + Filter results by title or app name (fuzzy, case-insensitive) Command: list-saves usage: legendary list-saves [-h] []