diff --git a/.context.yaml b/.context.yaml index 0967ef4..b00ceb4 100644 --- a/.context.yaml +++ b/.context.yaml @@ -1 +1,9 @@ -{} +TODO.md: + contexts: [] + note: The TODO file of this project + projects: + - tagg + tags: + - frr + - tag2 + - tag1 diff --git a/.index.yaml b/.index.yaml deleted file mode 100644 index 59ffc71..0000000 --- a/.index.yaml +++ /dev/null @@ -1,16 +0,0 @@ -contexts: - trial: - - ./TODO.md -files: - ./TODO.md: - contexts: - - trial - note: null - projects: [] - tags: - - tag1 - - tag2 -projects: {} -tags: - tag2: - - ./TODO.md diff --git a/dir/.context.yaml b/dir/.context.yaml new file mode 100644 index 0000000..cb4cca5 --- /dev/null +++ b/dir/.context.yaml @@ -0,0 +1,6 @@ +test.txt: + contexts: [] + projects: + - test + tags: + - test diff --git a/orvani.py b/orvani.py index 2dec13f..4d14cd0 100644 --- a/orvani.py +++ b/orvani.py @@ -1,7 +1,10 @@ import os +import sys import yaml import shutil from argparse import ArgumentParser as argp, SUPPRESS, RawTextHelpFormatter as raw +from rich.console import Console +from rich.table import Table # Defaults @@ -258,10 +261,13 @@ class OrvaniTag: continue if exact: if search == context: - result['found'] = self.INDEX[ctx][context] + if self.INDEX[ctx][context] not in result['found']: + result['found'] += self.INDEX[ctx][context] else: if search in context: - result['found'] = self.INDEX[ctx][context] + if self.INDEX[ctx][context] not in result['found']: + result['found'] += self.INDEX[ctx][context] + result['found'] = sorted(list(set(result['found'])), key=lambda x: x.count('/')) return result def __indexfolder(self, sub: str): @@ -279,12 +285,34 @@ class OrvaniTag: self.INDEX['files'].update( { path : self.DB[file]} ) for ctx in self.CTX.keys(): for item in self.DB[file][ctx]: - if item: - filelist = [path] - if ctx in self.INDEX: - if item in self.INDEX[ctx]: - filelist += self.INDEX[ctx][item] - self.INDEX.update( { ctx : { item : filelist } } ) + filelist = [path] + if ctx in self.INDEX: + if item in self.INDEX[ctx]: + filelist += self.INDEX[ctx][item] + self.INDEX[ctx][item] = filelist + +def mktable(query: str, index: dict): + table = Table(title=f"Results for `{query}`") + table.add_column("Path", justify="right", style="white", no_wrap=True) + table.add_column("Note", style="#cccccc") + table.add_column("Projects", justify="center", style="cyan") + table.add_column("Contexts", justify="center", style="magenta") + table.add_column("Tags", justify="center", style="green") + note = tags = projects = contexts = tags = '' + for file in index['found']: + path = file + fc = index['index']['files'][file] + if 'note' in fc: + note = fc['note'] + else: + note = '' + tags = ' '.join(['#' + tag for tag in fc['tags']]) + projects = ' '.join(['+' + p for p in fc['projects']]) + contexts = ' '.join(['@' + c for c in fc['contexts']]) + table.add_row(path, note, projects, contexts, tags) + + console = Console() + console.print(table) def main(): @@ -305,8 +333,8 @@ def main(): """ p = argp(description="OrvaniTagger", formatter_class=raw) - p.add_argument("--not-recursive", "-nr", action="store_true", help="Include subdirectories in search") - p.add_argument("--no-file_operation", "-nf", action="store_true", help="Copy/Move/Delete file, not just context") + p.add_argument("--not-recursive", "-nr", action="store_false", help="Include subdirectories in search") + p.add_argument("--no-file_operation", "-nf", action="store_false", help="Copy/Move/Delete file, not just context") 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("--cache", action="store_true", help="Cache index search (useful with deep directory trees)") @@ -350,9 +378,8 @@ def main(): if args.command in ['listtag', 'lst', 'lt'] or args.context_filter == 'tag': args.context_filter = 'tags' if query: - print(args.exact) r = orvani.list(query, args.path, args.context_filter, args.exact, args.not_recursive, args.cache) - print(r) + mktable(' '.join(sys.argv[1:]), r) elif args.command in ['copy', 'cp']: if args.file and args.context: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cfd6667 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +PyYAML==6.0 +rich==13.4.1