adding type search

This commit is contained in:
Amber 2024-02-05 10:10:00 +01:00
parent babce420c7
commit f16897721f
3 changed files with 16 additions and 3 deletions

View File

@ -9,6 +9,7 @@ cmd_parser = argparse.ArgumentParser(
cmd_parser.add_argument("path")
cmd_parser.add_argument("pattern")
cmd_parser.add_argument("-t", "--type")
# if -s is found in the command line cmd_args.show_children_nodes is True
cmd_parser.add_argument("-s", "--show-children-nodes", action="store_true")
## more than one occurrencies of -e option are appended in a list

View File

@ -19,9 +19,19 @@ class NerdTreeFind(NerdTree):
self.find_opts = find_opts
NerdTree.__init__(self, startpath, opts=opts)
def found_true_cond(self, test_node):
search_type = self.find_opts['type'] if self.find_opts.get('type') else None
if not search_type: test_type = True
else: test_type = (test_node['type'] == search_type)
test_match = True if self.re_item_name.match(test_node['name']) else False
return all([test_match, test_type])
def find_node_recursively(self, node):
# if node['name'] == self.item_name:
if self.re_item_name.match(node['name']):
# if self.re_item_name.match(node['name']):
if self.found_true_cond(node):
node_copy = node.copy()
node_copy.update({'color_formatter' : YELLOW, 'found' : 1})
self.results.append(node_copy)
@ -33,7 +43,8 @@ class NerdTreeFind(NerdTree):
self.find_node_recursively(item_child)
else:
# if item_child['name'] == self.item_name:
if self.re_item_name.match(item_child['name']):
# if self.re_item_name.match(item_child['name']):
if self.found_true_cond(item_child):
item_child_copy = item_child.copy()
item_child_copy.update({'color_formatter' : YELLOW, 'found' : 1})
self.results.append(item_child_copy)

View File

@ -17,7 +17,8 @@ if __name__ == '__main__':
# opts for find
find_opts = {
'dont_show_children_nodes': not show_children_nodes
'dont_show_children_nodes': not show_children_nodes,
'type' : cmd_args.type,
}
ntree = NerdTreeFind(path, opts=opts)