aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-11-25 19:59:33 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-11-25 19:59:33 +1300
commit3ec2a4181b016f7c56784db355ce1ed403547c58 (patch)
tree3d05be87f7bad9cc2c96034f71615caa67180b80 /bin
parentSimplify cf(1df) and cfr(1df) (diff)
downloaddotfiles-3ec2a4181b016f7c56784db355ce1ed403547c58.tar.gz
dotfiles-3ec2a4181b016f7c56784db355ce1ed403547c58.zip
Simplify cf(1df) with a find(1) command
This should also work for very large numbers of files
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cf18
1 files changed, 6 insertions, 12 deletions
diff --git a/bin/cf b/bin/cf
index 2076ddc2..362e4eba 100755
--- a/bin/cf
+++ b/bin/cf
@@ -14,20 +14,14 @@ for dir in "${@:-.}" ; do
continue
fi
- # 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 (sh(1) implementations
- # seem to vary on whether they include these)
- set -- "$dir"/.* "$@"
- [ -e "$1" ] || shift
- [ "$1" = "$dir"/. ] && shift
- [ "$1" = "$dir"/.. ] && shift
+ # Count the files
+ count=$(
+ find "$dir" ! -path "$dir" -prune -exec printf %.sx {} + |
+ wc -c
+ )
# Print the count and the dirname
- printf '%u\t%s\n' "$#" "$dir"
+ printf '%u\t%s\n' "$count" "$dir"
done
# Exit non-zero if a non-directory was given as an argument