nerd_tree follow_symbolic_link
This commit is contained in:
@ -12,6 +12,8 @@ cmd_parser.add_argument("path")
|
||||
cmd_parser.add_argument("-e", "--exclude", action="append")
|
||||
cmd_parser.add_argument("-l", "--list-directories-first", action="store_true")
|
||||
|
||||
cmd_parser.add_argument("-L", "--follow-symbolic-link", action="store_true")
|
||||
|
||||
# colorize
|
||||
cmd_parser.add_argument("-c", "--colorize", action="store_true")
|
||||
|
||||
|
22
src/tree.py
22
src/tree.py
@ -109,8 +109,14 @@ class NerdTree():
|
||||
colorize = self.opts['colorize'] if self.opts.get('colorize') is not None else False
|
||||
if not colorize:
|
||||
return d
|
||||
t = d['type']
|
||||
d['color_formatter'] = _tree_repr.get_color_formatter(t)
|
||||
|
||||
if d.get('is_symlink'):
|
||||
d['color_formatter'] = _tree_repr.get_color_formatter('l')
|
||||
d['target_color_formatter'] = _tree_repr.get_color_formatter(d['type'])
|
||||
else:
|
||||
d['color_formatter'] = _tree_repr.get_color_formatter(d['type'])
|
||||
d['target_color_formatter'] = ''
|
||||
|
||||
return d
|
||||
|
||||
def tree_struct(self, startpath, path=[]):
|
||||
@ -166,6 +172,10 @@ class NerdTree():
|
||||
'is_symlink' : start_dir_is_symlink,
|
||||
})
|
||||
|
||||
follow_symbolic_link = self.opts['follow_symbolic_link'] if self.opts.get('follow_symbolic_link') is not None else False
|
||||
if start_dir_is_symlink and not follow_symbolic_link:
|
||||
return d
|
||||
|
||||
# using listdir
|
||||
try:
|
||||
items = self.sort_items(startpath)
|
||||
@ -181,15 +191,14 @@ class NerdTree():
|
||||
if self.test_exclude_true(item):
|
||||
continue
|
||||
|
||||
|
||||
abs_path_item = startpath+item
|
||||
item_type, path_object = self.get_path_obj(abs_path_item)
|
||||
|
||||
|
||||
if path_object.is_dir():
|
||||
d['children'].append(self.tree_struct(abs_path_item, path=path[:]))
|
||||
else:
|
||||
is_symlink = path_object.is_symlink()
|
||||
|
||||
stat_item = path_object.lstat()
|
||||
stat_item_mode = stat_item.st_mode
|
||||
|
||||
@ -265,7 +274,10 @@ class NerdTree():
|
||||
nerd_tree_txt = rootnode_name
|
||||
|
||||
if (rootnode['is_symlink'] and rootnode.get('target', '')):
|
||||
nerd_tree_txt += ' -> %s' % (rootnode['target'],)
|
||||
if rootnode.get('target_color_formatter'):
|
||||
nerd_tree_txt += ' -> %s' % (rootnode['target_color_formatter'](rootnode['target']),)
|
||||
else:
|
||||
nerd_tree_txt += ' -> %s' % (rootnode['target'],)
|
||||
|
||||
items = rootnode.get('children') or []
|
||||
|
||||
|
@ -44,7 +44,10 @@ def produce_treeline(prec_seps, lsep):
|
||||
tomount = sep + item_name
|
||||
|
||||
if item.get('is_symlink') and item.get('target', ''):
|
||||
tomount += ' -> %s' % ((item['target'],))
|
||||
if item.get('target_color_formatter'):
|
||||
tomount += ' -> %s' % ((item['target_color_formatter'](item['target']),))
|
||||
else:
|
||||
tomount += ' -> %s' % ((item['target'],))
|
||||
|
||||
# if item.get('type') == 'd':
|
||||
# if item.get('nchildren') is not None:
|
||||
@ -81,5 +84,7 @@ def get_color_formatter(t):
|
||||
return BLUE
|
||||
if t == 'x':
|
||||
return GREEN
|
||||
if t == 'l':
|
||||
return CYAN
|
||||
return None
|
||||
|
||||
|
Reference in New Issue
Block a user