package

simple and robust package manager
Log | Files | Refs | README

commit f14761bb129f6889f9453a65b1b9becd210a656d
parent 4bf91a50b13811ca0c6762b9419a0573f491753d
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 13 Jan 2019 12:10:20 +0100

add the ltree helper to display pack-tree output as a tree

Diffstat:
Abin/ltree | 41+++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+), 0 deletions(-)

diff --git a/bin/ltree b/bin/ltree @@ -0,0 +1,41 @@ +#!/usr/bin/awk -f + +BEGIN { + LINE = "│ "; + NODE = "├─ "; + TAIL = "└─ "; + VOID = " "; + FS = "\t"; +} + +{ + count = split($2, paths, "/"); + for (i = 2; i < count; i++) LIST[NR":"i] = LINE; + + LIST[NR"path"] = $2; + LIST[NR":"count] = NODE; + LIST[NR":"1] = $1 " "; + LIST[NR"name"] = paths[count]; +} + +END { + for (i = 2; !stop; i++) { + stop = tail = 1; + for (l = NR; l > 0; l--) { + if (LIST[l":"i] == LINE && tail) { + LIST[l":"i] = VOID; + stop = 0; + } else if (LIST[l":"i] == NODE && tail) { + LIST[l":"i] = TAIL; + tail = stop = 0; + } else if (!LIST[l":"i]) { + tail = 1; + } + } + } + + for (nr = 1; nr <= NR; nr++) { + for (nf = 1; LIST[nr":"nf] != ""; nf++) printf "%s", LIST[nr":"nf]; + print LIST[nr"name"]; + } +}