print-paths-as-tree
accepts a list of paths from stdin and then prints them as a tree
-style tree.
$ cat << EOF | print-paths-as-tree
> dir1/one.file
> dir1/two.file
> dir2/one.file
> EOF
.
βββ dir1
β βββ one.file
β βββ two.file
βββ dir2
βββ one.file
2 directories, 3 files
Handy for nicely presenting affected files as a tree:
$ git diff --name-only | print-paths-as-tree
src
βββ components
β βββ avatar.tsx
β βββ list.tsx
βββ services
βββ users.ts
3 directories, 3 files
Super simple with go get
: go get github.com/christianscott/print-paths-as-tree
- Construct a tree from the paths, each segment inside the path becoming a node (i.e. the same as the file system). For example, the paths
src/one src/two
would become:
src
/ \
one two
- Perform a pre-order depth first traversal of the tree and print row for each node. The above tree would be visited in the order
src -> one -> two
. - To print a row, we need to print a "connector" for each ancestor of the current node, and then print the connector + the name of the final node. The type of connector depends on whether or not the node is its parents final child.