diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-02 00:20:12 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-09-02 00:31:25 +1200 |
commit | b59b96c291a5ddd02a58c9e91627cca5aadc6138 (patch) | |
tree | 9fe50993739a1a64a62846fe022046c867294ed2 | |
parent | Add tot(1df) (diff) | |
download | dotfiles-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.markdown | 3 | ||||
-rwxr-xr-x | bin/cfr | 12 | ||||
-rw-r--r-- | man/man1/cf.1df | 2 | ||||
-rw-r--r-- | man/man1/cfr.1df | 2 |
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 ... @@ -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> |