dot

packages and services management
Log | Files | Refs | README

commit 4f7f5a7e44e446c557216524e0fdab8bbad2b577
parent 5d862cf39a5c8a1643358f341c70bce46d255bd7
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue, 26 Dec 2017 20:33:34 +0100

added stat to pree command

Diffstat:
Mbin/pree | 42+++++++++++++++++-------------------------
1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/bin/pree b/bin/pree @@ -5,51 +5,43 @@ LC_COLLATE=C [ "$1" = -h ] && h=1 && shift || h=0 -find "$@" | sort -u | +find "$@" -exec stat -f %N%t%Sp {} + | sort -u | awk -v LINE='| ' -v NODE='|-- ' -v TAIL='`-- ' -v VOID=' ' -v HTML="$h" ' -BEGIN { - if (HTML) - print("<pre>"); -} - { - count = split($0, line, "/"); + split($0, stat); + count = split(stat[1], empty_v, "/"); if (HTML) { gsub("&", "\\&amp;"); gsub("<", "\\&gt;"); } - lines[NR":"0] = $0 + line_v[NR":"0] = $0 for (i = 1; i <= count; i++) - lines[NR":"i] = LINE; - lines[NR":"i - 1] = NODE; + line_v[NR":"i] = LINE; + line_v[NR":"i - 1] = NODE; } END { for (i = 1; !stop; i++) { stop = tail = 1; for (l = NR; l > 0; l--) { - if (lines[l":"i] == LINE && tail) { - lines[l":"i] = VOID; + if (line_v[l":"i] == LINE && tail) { + line_v[l":"i] = VOID; stop = 0; - } else if (lines[l":"i] == NODE && tail) { - lines[l":"i] = TAIL + } else if (line_v[l":"i] == NODE && tail) { + line_v[l":"i] = TAIL tail = stop = 0; - } else if (!lines[l":"i]) { + } else if (!line_v[l":"i]) { tail = 1; } } } for (l = 1; l <= NR; l++) { - name = lines[l":"0]; - sub(".*/", "", name); - for (i = 1; lines[l":"i]; i++) - printf("%s", lines[l":"i]); - if (HTML) - printf("<a href=\"%s\">%s</a>\n", lines[l":"0], name); - else - print(name); + split(line_v[l":"0], name, "\t"); + printf("%s ", name[2]) + for (i = 1; line_v[l":"i] != ""; i++) + printf("%s", line_v[l":"i]); + sub(".*/", "", name[1]); + print(name[1]); } - if (HTML) - print("</pre>"); }'