aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-09-02 00:20:12 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-09-02 00:31:25 +1200
commitb59b96c291a5ddd02a58c9e91627cca5aadc6138 (patch)
tree9fe50993739a1a64a62846fe022046c867294ed2 /bin
parentAdd tot(1df) (diff)
downloaddotfiles-b59b96c291a5ddd02a58c9e91627cca5aadc6138.tar.gz
dotfiles-b59b96c291a5ddd02a58c9e91627cca5aadc6138.zip
Reimplement cfr(1df) using cf(1df)
Resolves issue; not as fast as non-portable printf hack, but good enough. Also properly excludes root from the count.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cfr12
1 files changed, 7 insertions, 5 deletions
diff --git a/bin/cfr b/bin/cfr
index 36c5a7cf..691d4542 100755
--- a/bin/cfr
+++ b/bin/cfr
@@ -1,6 +1,8 @@
#!/bin/sh
-# Count files recursively with find(1); this includes the given directories
-# themselves and their subdirectories as entries, and correctly handles files
-# with newlines in their names. It's also all POSIX ... but on big directories,
-# it's *slow*.
-find "${@:-.}" -exec printf %.sx {} \; | wc -c
+# Count all descendants of given directories
+for dir in "${@:-.}" ; do
+ tot=$(find "$dir" -type d \
+ -exec sh -c 'cd -- "$1" && cf' _ {} \; |
+ cut -f1 | tot)
+ printf '%u\t%s\n' "$tot" "$dir"
+done