aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-09-01 22:59:08 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-09-01 22:59:08 +1200
commitcd63bce2f6f511078eb8fcf7a1c0e86eabb689d3 (patch)
treeb44887d54ec00d1f84716c390480fa7ebea33e0f
parentMove HISTSIZE and MAILCHECK to shrc (diff)
downloaddotfiles-cd63bce2f6f511078eb8fcf7a1c0e86eabb689d3.tar.gz
dotfiles-cd63bce2f6f511078eb8fcf7a1c0e86eabb689d3.zip
Fix POSIX non-compliance in cfr(1)
Which slows it down a *lot*; add an issue.
-rw-r--r--ISSUES.markdown3
-rwxr-xr-xbin/cfr6
2 files changed, 7 insertions, 2 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown
index 2715bfbb..27e28a0d 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -30,3 +30,6 @@ 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 9bb0e3bb..36c5a7cf 100755
--- a/bin/cfr
+++ b/bin/cfr
@@ -1,4 +1,6 @@
#!/bin/sh
# Count files recursively with find(1); this includes the given directories
-# themselves and their subdirectories as entries
-find "${@:-"$PWD"}" -printf . | wc -c
+# 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