show symbolic link
This commit is contained in:
parent
3a1d340f2d
commit
4976611793
10
README.md
10
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:<br />
|
In my opinion the better solution is:<br />
|
||||||
1. Clone the repository in your home folder
|
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
|
cd ~/nerd_tree
|
||||||
ln -s ~/nerd_tree/vfind.py ~/bin/vfind
|
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.<br />
|
all items matching the pattern are show in the result tree.<br />
|
||||||
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**
|
If you want to show the subtree expanded you can use the flag **-s**
|
||||||
|
|
||||||
```
|
```
|
||||||
|
17
src/tree.py
17
src/tree.py
@ -26,10 +26,10 @@ class NerdTree():
|
|||||||
|
|
||||||
if path_object.is_dir():
|
if path_object.is_dir():
|
||||||
item_type = 'd'
|
item_type = 'd'
|
||||||
elif path_object.is_file():
|
|
||||||
item_type = 'f'
|
|
||||||
elif path_object.is_symlink():
|
elif path_object.is_symlink():
|
||||||
item_type = 'l'
|
item_type = 'l'
|
||||||
|
elif path_object.is_file():
|
||||||
|
item_type = 'f'
|
||||||
|
|
||||||
assert item_type
|
assert item_type
|
||||||
|
|
||||||
@ -81,12 +81,15 @@ class NerdTree():
|
|||||||
start_dir_item_type, start_dir_object = self.get_path_obj(startpath)
|
start_dir_item_type, start_dir_object = self.get_path_obj(startpath)
|
||||||
stat_dir_item = start_dir_object.lstat()
|
stat_dir_item = start_dir_object.lstat()
|
||||||
|
|
||||||
|
start_dir_target = start_dir_object.resolve() if start_dir_object.is_symlink() else ''
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
path.append({
|
path.append({
|
||||||
'name' : rootnode,
|
'name' : rootnode,
|
||||||
'type' : start_dir_item_type,
|
'type' : start_dir_item_type,
|
||||||
'abs_path' : startpath,
|
'abs_path' : startpath,
|
||||||
'size' : stat_dir_item.st_size,
|
'size' : stat_dir_item.st_size,
|
||||||
|
'target' : str(start_dir_target),
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
path = [{
|
path = [{
|
||||||
@ -94,6 +97,7 @@ class NerdTree():
|
|||||||
'type' : start_dir_item_type,
|
'type' : start_dir_item_type,
|
||||||
'abs_path' : startpath,
|
'abs_path' : startpath,
|
||||||
'size' : stat_dir_item.st_size,
|
'size' : stat_dir_item.st_size,
|
||||||
|
'target' : str(start_dir_target),
|
||||||
}]
|
}]
|
||||||
|
|
||||||
d = {
|
d = {
|
||||||
@ -103,6 +107,7 @@ class NerdTree():
|
|||||||
'children' : [],
|
'children' : [],
|
||||||
'path': path,
|
'path': path,
|
||||||
'size' : stat_dir_item.st_size,
|
'size' : stat_dir_item.st_size,
|
||||||
|
'target' : str(start_dir_target),
|
||||||
}
|
}
|
||||||
|
|
||||||
# using listdir
|
# using listdir
|
||||||
@ -114,7 +119,7 @@ class NerdTree():
|
|||||||
d.setdefault('not_readable', 1)
|
d.setdefault('not_readable', 1)
|
||||||
|
|
||||||
for item in items:
|
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
|
continue
|
||||||
|
|
||||||
abs_path_item = startpath+item
|
abs_path_item = startpath+item
|
||||||
@ -125,11 +130,14 @@ class NerdTree():
|
|||||||
if path_object.is_dir():
|
if path_object.is_dir():
|
||||||
d['children'].append(self.tree_struct(abs_path_item, path=path[:]))
|
d['children'].append(self.tree_struct(abs_path_item, path=path[:]))
|
||||||
else:
|
else:
|
||||||
|
target = path_object.resolve() if path_object.is_symlink() else ''
|
||||||
|
|
||||||
path_copy = path[:]
|
path_copy = path[:]
|
||||||
path_copy.append({
|
path_copy.append({
|
||||||
'name' : item,
|
'name' : item,
|
||||||
'type' : item_type,
|
'type' : item_type,
|
||||||
'abs_path' : abs_path_item
|
'abs_path' : abs_path_item,
|
||||||
|
'target' : str(target),
|
||||||
})
|
})
|
||||||
|
|
||||||
d['children'].append({
|
d['children'].append({
|
||||||
@ -138,6 +146,7 @@ class NerdTree():
|
|||||||
'abs_path' : abs_path_item,
|
'abs_path' : abs_path_item,
|
||||||
'path' : path_copy,
|
'path' : path_copy,
|
||||||
'size' : stat_item.st_size,
|
'size' : stat_item.st_size,
|
||||||
|
'target' : str(target),
|
||||||
})
|
})
|
||||||
|
|
||||||
return d
|
return d
|
||||||
|
@ -43,6 +43,9 @@ def produce_treeline(prec_seps, lsep):
|
|||||||
item_name = item['name']
|
item_name = item['name']
|
||||||
tomount = sep + 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('type') == 'd':
|
||||||
# if item.get('nchildren') is not None:
|
# if item.get('nchildren') is not None:
|
||||||
# tomount += '(%s)' % (item['nchildren'],)
|
# tomount += '(%s)' % (item['nchildren'],)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user