dtree

Command line program to draw trees

For installation instructions, see the file INSTALL.

Manual

See https://strahinja.srht.site/man/dtree/dtree.1.html.

Examples

Format a tree using double-stroke box drawing characters:

printf "A\n\tB\n\t\tC\n\tD\n" | dtree -sd

tree(1) replacement:

find . -print | sed -E "s,[^/]+/,$(printf '\t'),g" | dtree

same, using ASCII characters:

find . -print | sed -E "s,[^/]+/,$(printf '\t'),g" | dtree -sa

poor man's findmnt(1) (depends on having /proc/mounts active):

sort -k2 /proc/mounts |
awk '{				# pp = previous pointer
	sl = $2;
	gsub("[^/]", "", sl);
	slashc = length(sl);	# slash count
	if ($2 != "/" &&
		slashc > prevsc[pp] &&
		substr($2,0,length(prev[pp])) == prev[pp])
	{
		for (i = 0; i < pp+1; i++)
			printf "\t";
		pp++;
	}
	else if ($2 != "/")
	{
		if (slashc < prevsc[pp] &&
			substr($2,0,length(prev[pp-1])) != prev[pp-1])
			pp--;
		for (i = 0; i < pp; i++)
			printf "\t";
	}
	print $2;
	prev[pp] = $2;		# previous mountpoint
	prevsc[pp] = slashc;	# previous slash count
}' |
dtree

Prerequisites

Install

$ git clone https://git.sr.ht/~strahinja/dtree
$ cd dtree
$ su
# make install

With got:

$ got clone https://git.sr.ht/~strahinja/dtree
$ got checkout dtree.git
$ cd dtree
$ su
# make install

Persistent build configuration file

The file config.mk will be sourced when building targets which also accept configuration through environment variables. For example, CPPFLAGS and PREFIX are specified in config.mk.

OpenBSD

Before running make(1), comment the CPPFLAGS definition in config.mk above the line with the “OpenBSD” comment and uncomment the one below it:

#CPPFLAGS	= -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \
#		  -D_XOPEN_SOURCE=700
# OpenBSD
CPPFLAGS	= -D_DEFAULT_SOURCE -D_POSIX_C_SOURCE=200809L \
		  -D_XOPEN_SOURCE=700 -D_BSD_SOURCE

Also, do the same for MANPREFIX:

#MANPREFIX	= $(DESTDIR)$(PREFIX)/share/man
# OpenBSD
MANPREFIX	= $(DESTDIR)$(PREFIX)/man

Install (Arch)

$ git clone https://aur.archlinux.org/dtree.git
$ cd dtree
$ makepkg -si

License

dtree - Command line program to draw trees
Copyright © 2023-2024 Страхиња Радић

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Generated by slweb © 2020-2024 Strahinya Radich.