blob: d006c6808186c57833cca8e1a7b7e3dab0ee37a9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# Count files
cf() {
local dirname
# Specify directory to check
dirname=${1:-$PWD}
# Error conditions
if [[ ! -e $dirname ]] ; then
printf 'bash: %s: %s does not exist\n' \
"$FUNCNAME" "$dirname" >&2
return 1
elif [[ ! -d $dirname ]] ; then
printf 'bash: %s: %s is not a directory\n' \
"$FUNCNAME" "$dirname" >&2
return 1
elif [[ ! -r $dirname ]] ; then
printf 'bash: %s: %s is not readable\n' \
"$FUNCNAME" "$dirname" >&2
return 1
fi
# Count files and print; use a subshell so options are unaffected
(
shopt -s dotglob nullglob
declare -a files=("$dirname"/*)
printf '%u\t%s\n' "${#files[@]}" "$dirname"
)
}
complete -A directory cf
|