shithub: rc

Download patch

ref: 7984f8c883882dc28da2ffb8424bbcf5f00e379f
parent: 7d31475a48e8ebf430fcb8c71c343c727ad095f7
author: qwx <qwx@sciops.net>
date: Fri Jun 13 03:46:15 EDT 2025

add unix-like tree(1)

slow as fuck but we want sorted and nicely formatted output.

--- /dev/null
+++ b/bin/tree
@@ -1,0 +1,34 @@
+#!/bin/rc
+walk -f $* | sort | awk '
+{
+	n = split($1, dir, "/")
+	if(n == 0)
+		p = "/"
+	else
+		p = "."
+	for(i=1; i<=n; i++){
+		c = dir[i]
+		if(!(c in par)){
+			par[c] = p
+			child[p,++nc[p]] = c
+		}
+		p = c
+	}
+}
+function printbranch(p, link, ind,	i, n){
+	n = nc[p]
+	print ind link p
+	if(ind != "" || link != "")
+		ind = ind (link == "└" ? " " : "│")
+	for(i=1; i<n; i++)
+		printbranch(child[p,i], "├", ind)
+	if(n >= 1)
+		printbranch(child[p,i], "└", ind)
+}
+END{
+	if("/" in nc)
+		printbranch("/", "", "")
+	if("." in nc)
+		printbranch(".", "", "")
+}
+'
--