-
-
Save denzuko/6a828c0f694d189de384f89ac1af9d79 to your computer and use it in GitHub Desktop.
Revisions
-
denzuko revised this gist
Jan 6, 2023 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ Leverging FZF for a user interface one can do fuzzy searching with a directory tree and document preview. The PTF.py creates that tree then colors the path thus giving a graph of the item searched. Example Usage includes: - More advance Poorman's Mindmap - Person/Contact Graph as a filesystem - Asset Mapping (with pass(1) and LDAP file system structures) - Maps with stow - Project Management / Kanboard -
Lanny created this gist
Jun 28, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ Outputs a limited file tree rooted at the current directory which highlights the position of the argument within the tree. Originally intended for FZF like so: ``` fzf --preview 'ptf.py {}' ``` Screenshot:  This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ #!/usr/bin/env python import sys import os def get_path(path): return os.path.join('.', os.path.normpath(path)).split(os.sep) def redify(s): return '\u001b[31m' + s + '\033[0m' def render_pathspec(pathspec, red): b = [] for idx, item in enumerate(pathspec): if idx == len(pathspec) - 1: b.append(redify('├') if red or item == 'r' else '├') b.append(redify('──') if red else '──') else: b.append(redify('│ ') if item == 'r' else '│ ') return ''.join(b) def print_level(name, pathspec, red=False): path = render_pathspec(pathspec, red) name = redify(name) if red else name print('%s%s' % (path, name)) def recur(idx, parts, pathspec): cur_path = os.path.join(*parts[:idx+1]) files = [f for f in os.scandir(cur_path)] is_final = idx == len(parts) - 2 on_path = True if not is_final: files = [f for f in files if f.is_dir()] for fidx, f in enumerate(files): red = False is_critical_path = f.name == parts[idx+1] if is_critical_path: red = True on_path = False new_pathspec = pathspec + ('r' if on_path else 'n') print_level( f.name, new_pathspec, red=red ) if not is_final and is_critical_path: recur(idx+1, parts, new_pathspec) if __name__ == '__main__': parts = get_path(sys.argv[1]) print(redify(parts[0])) recur(0, parts, '')