add include path

This commit is contained in:
Amber 2024-02-22 09:40:24 +01:00
parent 307bc5a15f
commit 8a71cee126
3 changed files with 15 additions and 1 deletions

View File

@ -15,6 +15,8 @@ cmd_parser.add_argument("-s", "--show-children-nodes", action="store_true")
## more than one occurrencies of -e option are appended in a list
cmd_parser.add_argument("-e", "--exclude", action="append")
cmd_parser.add_argument("-i", "--include", action="append")
# start the command line parsing
cmd_args = cmd_parser.parse_args()

View File

@ -82,6 +82,18 @@ class NerdTreeFind(NerdTree):
if not results:
return {}
## filter results
items_to_include= self.find_opts['items_to_include'] if self.find_opts.get('items_to_include') is not None else []
if items_to_include:
filtered_results = []
items_to_include_set = set(items_to_include)
for res in results:
pathset = set(path['name'] for path in res['path'])
if not items_to_include_set.intersection(pathset):
continue
filtered_results.append(res.copy())
results = filtered_results
dont_show_children_nodes = self.find_opts['dont_show_children_nodes'] if self.find_opts.get('dont_show_children_nodes') is not None else False
self.opts['dont_show_children_nodes'] = dont_show_children_nodes
@ -115,7 +127,6 @@ class NerdTreeFind(NerdTree):
if not islastpath: children.append(pcopy)
else : children.append(node)
# key size is lost in preceding code!!!!!!!!!!!!
self.compute_aggregate_recursively(tree_struct)
return tree_struct

View File

@ -19,6 +19,7 @@ if __name__ == '__main__':
find_opts = {
'dont_show_children_nodes': not show_children_nodes,
'type' : cmd_args.type,
'items_to_include' : cmd_args.include or [],
}
ntree = NerdTreeFind(path, opts=opts)