adding type search
This commit is contained in:
parent
babce420c7
commit
f16897721f
|
@ -9,6 +9,7 @@ cmd_parser = argparse.ArgumentParser(
|
||||||
|
|
||||||
cmd_parser.add_argument("path")
|
cmd_parser.add_argument("path")
|
||||||
cmd_parser.add_argument("pattern")
|
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
|
# 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")
|
cmd_parser.add_argument("-s", "--show-children-nodes", action="store_true")
|
||||||
## more than one occurrencies of -e option are appended in a list
|
## more than one occurrencies of -e option are appended in a list
|
||||||
|
|
|
@ -19,9 +19,19 @@ class NerdTreeFind(NerdTree):
|
||||||
self.find_opts = find_opts
|
self.find_opts = find_opts
|
||||||
NerdTree.__init__(self, startpath, opts=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):
|
def find_node_recursively(self, node):
|
||||||
# if node['name'] == self.item_name:
|
# 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 = node.copy()
|
||||||
node_copy.update({'color_formatter' : YELLOW, 'found' : 1})
|
node_copy.update({'color_formatter' : YELLOW, 'found' : 1})
|
||||||
self.results.append(node_copy)
|
self.results.append(node_copy)
|
||||||
|
@ -33,7 +43,8 @@ class NerdTreeFind(NerdTree):
|
||||||
self.find_node_recursively(item_child)
|
self.find_node_recursively(item_child)
|
||||||
else:
|
else:
|
||||||
# if item_child['name'] == self.item_name:
|
# 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 = item_child.copy()
|
||||||
item_child_copy.update({'color_formatter' : YELLOW, 'found' : 1})
|
item_child_copy.update({'color_formatter' : YELLOW, 'found' : 1})
|
||||||
self.results.append(item_child_copy)
|
self.results.append(item_child_copy)
|
||||||
|
|
3
vfind.py
3
vfind.py
|
@ -17,7 +17,8 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
# opts for find
|
# opts for find
|
||||||
find_opts = {
|
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)
|
ntree = NerdTreeFind(path, opts=opts)
|
||||||
|
|
Loading…
Reference in New Issue