#!/bin/sh # compact version of tree # max directories depth level=$(echo "$@" | sed -nE 's/.*-L ?([0-9]).*/\1/p') # indentation of leaf directory begin=$(printf "%$((level - 2))s" | sed 's/ /│   /g') # indentation of leaf files line=$(printf "%$((level - 1))s" | sed 's/ /│   /g') # limit to 6 files and add ellipses res=$(tree --dirsfirst --noreport -L 2 -C "$@" \ | awk -v begin="$begin" -v line="$line" ' ($0 ~ "^"begin"├|└") {count=0} ($0 ~ "^"line) {count+=1} {if (count <= 5){print $0} if(count == 6){print line"├── ..."}} ' \ | sed 's/ / /g') # use a pager when output doesn't fit the screen if test $(printf "%s\n" "$res" | wc -l) -gt $(tput lines) then printf "%s\n" "$res" | $PAGER -RSicX else printf "%s\n" "$res" fi