From 4976611793ca5aad838360985748be85aea3e4f7 Mon Sep 17 00:00:00 2001 From: Amber Date: Mon, 5 Feb 2024 17:05:39 +0100 Subject: [PATCH] show symbolic link --- README.md | 10 ++++++++-- src/tree.py | 17 +++++++++++++---- src/tree_repr.py | 3 +++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b52a20f..b87ff33 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ You can search in a particular subtree for files or folders that match a regular In my opinion the better solution is:
1. Clone the repository in your home folder -2. Go to your home folder and make a symbolic link to the command, in your ~/bin folder +2. Go to your home folder and make a symbolic link to the command in your ~/bin folder ``` cd ~/nerd_tree ln -s ~/nerd_tree/vfind.py ~/bin/vfind @@ -23,7 +23,13 @@ vfind ~/nerd_tree/ "(.*)rem(.*)" ``` all items matching the pattern are show in the result tree.
-The folder matching the pattern are show with information about the total number of files and the size of the subtree. +You can use as pattern any valid regular expression, for example pattern as this + +``` +vfind ~/nerd_tree/ "(.*)rem|tree(.*)" +``` + +The folder matching the pattern are show collapsed with information about the total number of files and the size of the subtree. If you want to show the subtree expanded you can use the flag **-s** ``` diff --git a/src/tree.py b/src/tree.py index 054e993..f32286f 100644 --- a/src/tree.py +++ b/src/tree.py @@ -26,10 +26,10 @@ class NerdTree(): if path_object.is_dir(): item_type = 'd' - elif path_object.is_file(): - item_type = 'f' elif path_object.is_symlink(): item_type = 'l' + elif path_object.is_file(): + item_type = 'f' assert item_type @@ -81,12 +81,15 @@ class NerdTree(): start_dir_item_type, start_dir_object = self.get_path_obj(startpath) stat_dir_item = start_dir_object.lstat() + start_dir_target = start_dir_object.resolve() if start_dir_object.is_symlink() else '' + if path: path.append({ 'name' : rootnode, 'type' : start_dir_item_type, 'abs_path' : startpath, 'size' : stat_dir_item.st_size, + 'target' : str(start_dir_target), }) else: path = [{ @@ -94,6 +97,7 @@ class NerdTree(): 'type' : start_dir_item_type, 'abs_path' : startpath, 'size' : stat_dir_item.st_size, + 'target' : str(start_dir_target), }] d = { @@ -103,6 +107,7 @@ class NerdTree(): 'children' : [], 'path': path, 'size' : stat_dir_item.st_size, + 'target' : str(start_dir_target), } # using listdir @@ -114,7 +119,7 @@ class NerdTree(): d.setdefault('not_readable', 1) for item in items: - if item in self.opts.get('items_to_exclude') or []: + if item in (self.opts.get('items_to_exclude') or []): continue abs_path_item = startpath+item @@ -125,11 +130,14 @@ class NerdTree(): if path_object.is_dir(): d['children'].append(self.tree_struct(abs_path_item, path=path[:])) else: + target = path_object.resolve() if path_object.is_symlink() else '' + path_copy = path[:] path_copy.append({ 'name' : item, 'type' : item_type, - 'abs_path' : abs_path_item + 'abs_path' : abs_path_item, + 'target' : str(target), }) d['children'].append({ @@ -138,6 +146,7 @@ class NerdTree(): 'abs_path' : abs_path_item, 'path' : path_copy, 'size' : stat_item.st_size, + 'target' : str(target), }) return d diff --git a/src/tree_repr.py b/src/tree_repr.py index 13eb7ad..307a28d 100644 --- a/src/tree_repr.py +++ b/src/tree_repr.py @@ -43,6 +43,9 @@ def produce_treeline(prec_seps, lsep): item_name = item['name'] tomount = sep + item_name + if item['type'] == 'l' and item['target']: + tomount += ' -> %s' % ((item['target'],)) + # if item.get('type') == 'd': # if item.get('nchildren') is not None: # tomount += '(%s)' % (item['nchildren'],)