misc/scripts/t
2022-11-16 01:10:58 +01:00

26 lines
765 B
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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