1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-09-19 09:44:05 -07:00
rc/sh/busiest

24 lines
646 B
Bash
Executable file

#!/usr/bin/env zsh
# compat: -ash -bash -dash -hush -ksh -mksh -oksh -osh -posh -yash +zsh
busiest() { ### @-
### list directories in descending order by the number of files in them,
### counted recursively.
###
### ```
### $ cd && busiest | head -n3
### 144181 src
### 48840 work
### 21042 play
### ```
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
local c= d=
for d in *(FDN); do
print $(find $d 2>/dev/null | wc -l) $d
done | sort -nr | while read c d; do
echo -E $c $d
done
[ -z $d ] && return 1
}
[ -n "${preload+-}" ] || busiest "$@"