aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-31 20:44:52 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-31 20:44:52 +1200
commit23bb6ceaa9693a72cc3b85286d76d607effac604 (patch)
tree0353468f3ffa7dbbb06621301f6be6f432f77ccc
parentChange cf(1) to POSIX sh and multi args (diff)
downloaddotfiles-23bb6ceaa9693a72cc3b85286d76d607effac604.tar.gz
dotfiles-23bb6ceaa9693a72cc3b85286d76d607effac604.zip
Switch to slightly faster cf(1) method
-rwxr-xr-xbin/cf23
1 files changed, 14 insertions, 9 deletions
diff --git a/bin/cf b/bin/cf
index 6b7bd9d8..3063d58b 100755
--- a/bin/cf
+++ b/bin/cf
@@ -2,19 +2,24 @@
# Count entries in a given set of directories
ex=0
for dir in "${@:-.}" ; do
+
+ # Warn if a non-directory was given, flag errors, but continue
if ! [ -d "$dir" ] ; then
printf >&2 'cf: %s: not a directory\n' "$dir"
ex=1
continue
fi
- c=0
- for ent in "$dir"/* "$dir"/.* ; do
- [ -e "$ent" ] || continue
- case $ent in
- */.|*/..) ;;
- *) c=$((c+1)) ;;
- esac
- done
- printf '%u\t%s\n' "$c" "$dir"
+
+ # Add files matching glob, shift them off if unexpanded (first and only
+ # entry doesn't exist)
+ set -- "$dir"/*
+ [ -e "$1" ] || shift
+
+ # Add dot files, shift off the "." and ".." entries
+ set -- "$dir"/.* "$@"
+ shift 2
+
+ # Print number of parameters
+ printf '%u\t%s\n' "$#" "$dir"
done
exit "$ex"