All pastes #960362 Raw Edit

Untitled

public text v1 · immutable
#960362 ·published 2008-03-28 01:27 UTC
rendered paste body
#!/bin/bash

index() {
		usedext=0
		for (( i=0; i < ${#exts[@]}; i++ ));  do
			if [ "${exts[i]}" = "$1" ]; then
				usedext=1
				(( counts[i]++ ))
				i=${#exts[@]}
			fi
		done
		if [ $usedext = "0" ]; then
			exts+=("$1")
			counts+=("1")
		fi
}

exts=("*" ".*" "*/" ".*/")
counts=(0 0 0 0)
shopt -s dotglob

path="$PWD"; [ $1 ] && [ -d $1 ] && path="$1"

for file in "$path"/*; do
	file="${file##*/}"
	# exclude . and ..
	[ "$file" != "." ] && [ "$file" != ".." ] && \
	# directories separately
	if [ -d "$path/$file" ]; then
		if [[ "$file" = .* ]]; then
			index ".*/"
		else
			index "*/"
		fi
	else
		if [[ "$file" = *.* ]]; then
			if [[ "$file" = .* ]]; then
				index ".*"
			else
				index "${file##*.}"
			fi
		else
			index "*"
		fi
	fi
done

for (( i=0; i < ${#exts[@]}; i++ ));  do
	(( ${counts[i]} != 0 )) && echo ${exts[i]}$'\t'${counts[i]}
done