diff --git a/pyesearch.py b/pyesearch.py index 194700c..4eafcd6 100755 --- a/pyesearch.py +++ b/pyesearch.py @@ -4,7 +4,6 @@ import sys import os import subprocess from glob import glob -from functools import partial as p import re @@ -83,7 +82,7 @@ def find(query, paths, depth=None): depth_args = ["-mindepth", f"{depth}", "-maxdepth", f"{depth}"] if depth is not None else [] proc = subprocess.run( - ["find", *paths, *depth_args, "-iname", f"*query*", "-print0"], + ["find", *paths, *depth_args, "-iname", f"*{query}*", "-print0"], check=True, stdout=subprocess.PIPE ) return list_from_print0(proc.stdout) @@ -140,20 +139,28 @@ def ebuild_info(path, repos): def longest_category_and_nameversion(infos, default_repo=None): return ( max(len(x["category"]) for x in infos), - max(len(f"{x['name']}-{x['PV']}" + (f"::{x['repo']}" if x["repo"] != default_repo else "")) for x in infos) + max( + len(f"{x['name']}-{x['PV']}") + + len(f"::{x['repo']}" if x["repo"] != default_repo else "") + for x in infos) ) def format_item(info, longest_cat=0, longest_namever=0, default_repo=None): - name_version = f"{info['name']}-{info['PV']}" category_colour = "\x1b[0m" if info["installed"] else "\x1b[0;90m" + name_version = f"{info['name']}-{info['PV']}" name_colour = "\x1b[92m" if info["installed"] else "\x1b[36m" - repo = f"::{info['repo']}" if info["repo"] != default_repo else "" - name = f"{name_version}{category_colour}{repo}" - filler = (f"\x1b[{'92' if info['installed'] else '90'}m " + ("." * (longest_namever - len(name_version) - len(repo)))) if info["description"] else "" + description_colour = "\x1b[0m" if not info["installed"] else "" + description = info["description"] if info["description"] else "" - return f"{category_colour}{info['category']:>{longest_cat}}/{name_colour}{name}{filler}" + ("\x1b[0m" if not info["installed"] else "") + (f" {info['description']}" if info["description"] else "") + filler = ( + f"\x1b[{'92' if info['installed'] else '90'}m " + + ("." * (longest_namever - len(name_version) - len(repo))) + ) if info["description"] else "" + return f"{category_colour}{info['category']:>{longest_cat}}/" \ + f"{name_colour}{name_version}{category_colour}{repo}{filler} " \ + f"{description_colour}{description}"