diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-31 20:44:52 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-31 20:44:52 +1200 |
commit | 23bb6ceaa9693a72cc3b85286d76d607effac604 (patch) | |
tree | 0353468f3ffa7dbbb06621301f6be6f432f77ccc | |
parent | Change cf(1) to POSIX sh and multi args (diff) | |
download | dotfiles-23bb6ceaa9693a72cc3b85286d76d607effac604.tar.gz dotfiles-23bb6ceaa9693a72cc3b85286d76d607effac604.zip |
Switch to slightly faster cf(1) method
-rwxr-xr-x | bin/cf | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -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" |