#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2009 Christopher Bratusek		#
#							#
#########################################################

count_files_help()
{
	white=$(bs_ng_echo $white)
	orange=$(bs_ng_echo $orange)
	iceblue=$(bs_ng_echo $iceblue)
	green=$(bs_ng_echo $green)

	echo -e "\n${white}Usage:"
	echo -e "\n${orange}count_files${white} | ${green}+h ${iceblue}[count files and folders - include hidden ones] \
	\n${orange}count_files${white} | ${green}-h ${iceblue}[count files and folders - exclude hidden ones] \
	\n${orange}count_files${white} | ${green}+d ${iceblue}[count folders - include hidden ones] \
	\n${orange}count_files${white} | ${green}-d ${iceblue}[count folders - exclude hidden ones] \
	\n${orange}count_files${white} | ${green}+f ${iceblue}[count files - include hidden ones] \
	\n${orange}count_files${white} | ${green}-f ${iceblue}[count files - exclude hidden ones]\n"
	tput sgr0
}

count_files ()
{
	case $1 in
		*+h)
			echo $(($(ls --color=no -1 -la . | grep -v ^l | wc -l)-1))
		;;

		*-h)
			echo $(($(ls --color=no -1 -l . | grep -v ^l | wc -l)-1))
		;;

		*+d)
			echo $(($(ls --color=no -1 -la . | grep -v ^- | wc -l)-1))
		;;

		*-d)
			echo $(($(ls --color=no -1 -l . | grep -v ^- | wc -l)-1))
		;;

		*+f)
			echo $(($(ls --color=no -1 -la . | grep -v ^d | wc -l)-1))
		;;

		*-f)
			echo $(($(ls --color=no -1 -l . | grep -v ^d | wc -l)-1))
		;;

		*)
			count_files_help
		;;
	esac
}

