aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--ISSUES.markdown3
-rwxr-xr-xbin/cfr12
-rw-r--r--man/man1/cf.1df2
-rw-r--r--man/man1/cfr.1df2
4 files changed, 11 insertions, 8 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown
index 27e28a0d..2715bfbb 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -30,6 +30,3 @@ Known issues
* sxhkd(1) might be nicer than xbindkeys; it's in Debian Testing now
* Maybe I should port some of the prompt functions to POSIX sh so I don't
have to maintain parallel versions for bash, pdksh, and zsh
-* find(1) -printf isn't POSIX, and isn't even in OpenBSD's version. Is there
- a nicer way to do cfr(1df) efficiently while still handling edge cases like
- files with newlines? -exec printf . works, but it's sloooow ...
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
diff --git a/man/man1/cf.1df b/man/man1/cf.1df
index b092c9eb..91bb9e93 100644
--- a/man/man1/cf.1df
+++ b/man/man1/cf.1df
@@ -15,5 +15,7 @@ dir1 dir2
counts all the entries in the given directories using glob
expansion and prints the count. It defaults to the current
directory.
+.SH SEE ALSO
+cfr(1df)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/cfr.1df b/man/man1/cfr.1df
index 0208023d..ab69b347 100644
--- a/man/man1/cfr.1df
+++ b/man/man1/cfr.1df
@@ -14,5 +14,7 @@ dir1 dir2
.B cf
counts all the entries in the directory trees rooted at the given arguments,
and prints the total. It defaults to the current directory.
+.SH SEE ALSO
+cf(1df), tot(1df)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>