scripts/t: handle arbitrary depths
This commit is contained in:
parent
c8b37c7b04
commit
9381733ab1
18
scripts/t
18
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
|
||||
|
Loading…
Reference in New Issue
Block a user