From 90f3198dacb4290a9f7ee39c2d80260dd63e9892 Mon Sep 17 00:00:00 2001 From: randogoth Date: Fri, 9 Jun 2023 02:17:33 +0300 Subject: [PATCH] files or folders filter --- orvani/cmd.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/orvani/cmd.py b/orvani/cmd.py index bafb603..0819bfa 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -7,7 +7,7 @@ from rich.table import Table from orvani import OrvaniTag, CONTEXT_FILE, CACHE_FILE, CONTEXTS from plugins import frontmatter, hashdoubleslash, id3, office -def mktable(query: str, index: dict): +def mktable(query: str, index: dict, filter=None): console = Console() if len(index['found']) > 0: table = Table(title=f"Results for `{query}`") @@ -17,6 +17,11 @@ def mktable(query: str, index: dict): for i, c in enumerate(ctx): table.add_column(ctx[i].title(), style=styles[i]) for file in index['found']: + item = Path(file) + if filter == 'files' and not item.is_file(): + continue + if filter == 'dirs' and not item.is_dir(): + continue fc = index['index']['items'][file] elements = [] elements.append(file) @@ -64,6 +69,8 @@ def main(): p.add_argument("--no-plugins", "-np", action="store_false", help="Don't use plug-ins to search file metadata") p.add_argument("--path", "-p", action="store", type=str, help="List/search custom path", default='') p.add_argument("--exact", "-e", action="store_true", help="Match exact search term") + p.add_argument("--files", "-f", action="store_true", help="Only show files, ignore folders") + p.add_argument("--dirs", "-d", action="store_true", help="Only show directories, ignore files") p.add_argument("--either", "-or", action="store_true", help="Combine search terms by OR instead of AND") p.add_argument("--cache", "-c", action="store_true", help="Cache index search (useful with deep directory trees)") p.add_argument("--delete-cache", "-dc", action="store_true", help="Delete cache file") @@ -106,7 +113,12 @@ def main(): query = [args.file] + args.context if query: r = orvani.list(args.path, args.exact, args.either, args.not_recursive, args.cache, args.delete_cache, *query) - mktable(' '.join(sys.argv[1:]), r) + filter = None + if args.files: + filter = 'files' + elif args.dirs: + filter = 'dirs' + mktable(' '.join(sys.argv[1:]), r, filter) elif args.command in ['copy', 'cp']: if args.file and args.context: