diff --git a/scripts/t b/scripts/t index 6e0a990..ca0cfa1 100755 --- a/scripts/t +++ b/scripts/t @@ -1,11 +1,25 @@ #!/bin/sh # compact version of tree + +# max directories depth +level=$(echo "$@" | sed -nE 's/.*-L ?([0-9]).*/\1/p') +# indentatiof 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 '/^├|└/{l1=0} /^│/{l1+=1} {if (l1 <= 5){print $0} if(l1 == 6){print "│   ├── ..."}}' \ +| 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" | less -RSicX +then printf "%s\n" "$res" | $PAGER -RSicX else printf "%s\n" "$res" fi