[READ-ONLY] Mirror of https://github.com/probablykasper/my-bash-scripts. My personal bash scripts
cli
0

Configure Feed

Select the types of activity you want to include in your feed.

Create ls-with-item-count

Kasper (Mar 13, 2022, 9:56 PM +0100) 70ab6295 3422cdff

+33
+33
bin/ls-with-item-count
··· 1 + #! /bin/zsh 2 + 3 + help() { 4 + echo "List directories by item count" 5 + echo "" 6 + echo "`color 2 Usage:` list-dirs <path> <min-depth> [max-depth]" 7 + echo "" 8 + echo "`color 2 Example:` list-dirs . 1" 9 + echo "" 10 + } 11 + 12 + # no args 13 + if [[ "$#" < 1 ]]; then help; exit 0; fi 14 + 15 + ARG="$1" 16 + MINDEPTH="$2" 17 + MAXDEPTH="$3" 18 + 19 + if [[ -z "$MAXDEPTH" ]]; then 20 + MAXDEPTH="$MINDEPTH" 21 + fi 22 + 23 + if [[ "$ARG" && "$MINDEPTH" ]]; then 24 + DIRS=$(find "$ARG" -type d -mindepth "$MINDEPTH" -maxdepth "$MAXDEPTH") 25 + # echo "$DIRS" 26 + IFS="\n" 27 + while read -r LINE; do 28 + COUNT=$(find "$LINE" -name "*" | wc -l) 29 + echo "$COUNT $LINE" 30 + done <<< "$DIRS" 31 + else 32 + help 33 + fi