dot

packages and services management
Log | Files | Refs | README

commit 7f6977009a7c1f4e1b29bc5bc92432e96fe55ce0
parent f1473dd5f3e13ec1c2a6cfc10a7cb74147596d61
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Mon, 31 Jul 2017 01:02:25 +0200

scripts/bin/tree: generate tree from find command or anything else

Diffstat:
Ascripts/bin/tree | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+), 0 deletions(-)

diff --git a/scripts/bin/tree b/scripts/bin/tree @@ -0,0 +1,61 @@ +sort | awk ' +BEGIN { + o = 1 + IFS = "\0" +} + +{ + gsub(/&/, "&amp;", $0) + gsub(/</, "$lt;", $0) + + subtree = 0 + s = split($0, line, "/") + + for (i = 1; i <= s; i++) { + if (line[i] == prev[i] && !subtree) { + out[o"]["i] = "| " + + } else { + subtree = 1 + out[o"]["i] = "|-- " + out[o"]["0] = line[i] + count[o] = i + o++ + + if (i < s) + for (j = 1; j <= i; j++) + out[o"]["j] = "| " + } + + prev[i] = line[i] + } + prev[i] = "" +} + +END { + for (i = 1; !stop; i++) { + last = 1 + stop = 1 + for (l = o; l > 0; l--) { + + if (out[l"]["i] == "| " && last) { + out[l"]["i] = " " + stop = 0 + + } else if (out[l"]["i] == "|-- " && last) { + out[l"]["i] = "`-- " + last = 0 + stop = 0 + + } else if (out[l"]["i] <= count[l]) { + last = 1 + } + } + } + + for (l = 1; l <= o; l++) { + for (i = 1; out[l"]["i]; i++) + printf "%s", out[l"]["i] + print out[l"]["0] + } +}'