dot

packages and services management
Log | Files | Refs | README

commit f27631a6ba94d7f3ecdedd4eefc7f256b11c2ae6
parent 52b64d6d247a3403a2468206190f8c462c979489
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Mon, 31 Jul 2017 08:00:50 +0200

scripts/bin/tree: simpler version

First add missing intermediate nodes, then split at "/"
into an array of strings, then replace the strings with
the tree delimiters, finally clean useless delimiters.

Diffstat:
Dmbsync/.build.swp | 0
Mscripts/bin/tree | 71+++++++++++++++++++++++------------------------------------------------
Mscripts/bin/www-git | 47+++++++++++++++++++++++++++++++++--------------
3 files changed, 56 insertions(+), 62 deletions(-)

diff --git a/mbsync/.build.swp b/mbsync/.build.swp Binary files differ. diff --git a/scripts/bin/tree b/scripts/bin/tree @@ -1,61 +1,36 @@ -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] = "| " - } - +awk '{ + gsub("&", "\&amp;"); gsub("<", "\&lt;") + do { print } while (sub("/[^/]*$", "")) +}' | sort -u | awk '{ + count = split($0, line, "/") + for (i = 1; i < count; i++) { + lines[NR"]["0] = $0 + lines[NR"]["i] = "| " prev[i] = line[i] } + lines[NR"]["i - 1] = "|-- " prev[i] = "" -} - -END { +} 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 = tail = 1 + for (l = NR; l > 0; l--) { + if (lines[l"]["i] == "| " && tail) { + lines[l"]["i] = " " stop = 0 - } else if (out[l"]["i] == "|-- " && last) { - out[l"]["i] = "`-- " - last = 0 - stop = 0 + } else if (lines[l"]["i] == "|-- " && tail) { + lines[l"]["i] = "`-- " + tail = stop = 0 - } else if (out[l"]["i] <= count[l]) { - last = 1 + } else if (!lines[l"]["i]) { + tail = 1 } } } - for (l = 1; l <= o; l++) { - for (i = 1; out[l"]["i]; i++) - printf "%s", out[l"]["i] - print out[l"]["0] + for (l = 1; l < NR; l++) { + for (i = 1; lines[l"]["i]; i++) + printf "%s", lines[l"]["i] + print lines[l"]["0] } }' diff --git a/scripts/bin/www-git b/scripts/bin/www-git @@ -24,22 +24,42 @@ cd "git/$NAME" || exit 1 { printf '%s\n' "$HEADER" - git -C "$1" ls-files | sort | awk -F '\0' '{ - gsub(/&/, "&amp;", $0) - gsub(/</, "$lt;", $0) - margin = "" - subtree = 0 + awk '{ + gsub("&", "\&amp;"); gsub("<", "\&lt;") + do { print } while (sub("/[^/]*$", "")) + }' | sort -u | awk '{ count = split($0, line, "/") - for (i = 1; i <= count; i++) { - if (line[i] != prev[i] || subtree) { - printf "%s`-- <a href=\"file/%s\">%s</a>\n", \ - margin, $0, line[i] - subtree = 1 + for (i = 1; i < count; i++) { + lines[NR"]["0] = $0 + lines[NR"]["i] = "| " + prev[i] = line[i] + } + lines[NR"]["i - 1] = "|-- " + prev[i] = "" + } END { + for (i = 1; !stop; i++) { + stop = tail = 1 + for (l = NR; l > 0; l--) { + if (lines[l"]["i] == "| " && tail) { + lines[l"]["i] = " " + stop = 0 + + } else if (lines[l"]["i] == "|-- " && tail) { + lines[l"]["i] = "`-- " + tail = stop = 0 + + } else if (!lines[l"]["i]) { + tail = 1 + } } + } - margin = margin "| " - prev[i] = line[i] + for (l = 1; l < NR; l++) { + for (i = 1; lines[l"]["i]; i++) + printf "%s", lines[l"]["i] + sub(".*/", "<a href=\"" lines[l"]["0] "\">", lines[l"]["0]) + print lines[l"]["0] "</a>" } }' @@ -57,8 +77,7 @@ cd "git/$NAME" || exit 1 } > index.html - -# --- ./file/ -------------------------------------------------------------------- +# --- ./file/ ------------------------------------------------------------------ git -C "$1" ls-files | while IFS='' read -r file do