files or folders filter
This commit is contained in:
parent
91ef2e9cbd
commit
90f3198dac
1 changed files with 14 additions and 2 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue