aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-11-25 17:25:48 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-11-25 17:25:48 +1300
commit7021f36c94bc65a6164b559f97d9e8438bdccfd9 (patch)
tree06140233b7ca684d439c94de591e5ca681205208 /bin
parentMerge branches 'freebsd' and 'openbsd' (diff)
downloaddotfiles-7021f36c94bc65a6164b559f97d9e8438bdccfd9.tar.gz
dotfiles-7021f36c94bc65a6164b559f97d9e8438bdccfd9.zip
Simplify cf(1df) and cfr(1df)
It turns out `-exec foo {} +` is in fact POSIX behaviour (since SUSv3 as far as I can tell).
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cf25
-rwxr-xr-xbin/cfr6
2 files changed, 5 insertions, 26 deletions
diff --git a/bin/cf b/bin/cf
index d245fec1..2076ddc2 100755
--- a/bin/cf
+++ b/bin/cf
@@ -2,23 +2,6 @@
# Count entries in a given set of directories
self=cf
-# Parse options out
-while getopts 'o' opt ; do
- case $opt in
-
- # Print only the count, not the filename
- o) only=1 ;;
-
- # Unknown option
- \?)
- printf >&2 '%s: Unknown option %s\n' \
- "$self" "$opt"
- exit 2
- ;;
- esac
-done
-shift "$((OPTIND-1))"
-
# Iterate over remaining non-option arguments (directories); default to current
# directory if none given
for dir in "${@:-.}" ; do
@@ -43,12 +26,8 @@ for dir in "${@:-.}" ; do
[ "$1" = "$dir"/. ] && shift
[ "$1" = "$dir"/.. ] && shift
- # Print either just the count, or the count and the dirname
- if [ -n "$only" ] ; then
- printf '%u\n' "$#"
- else
- printf '%u\t%s\n' "$#" "$dir"
- fi
+ # Print the count and the dirname
+ printf '%u\t%s\n' "$#" "$dir"
done
# Exit non-zero if a non-directory was given as an argument
diff --git a/bin/cfr b/bin/cfr
index f5eafef5..31b9830b 100755
--- a/bin/cfr
+++ b/bin/cfr
@@ -6,8 +6,8 @@ for dir in "${@:-.}" ; do
ex=1
continue
fi
- printf '%u\t%s\n' \
- "$(find "$dir" -type d -exec cf -o -- {} \; | tot)" \
- "$dir"
+ count=$(find "$dir" -exec printf %.sx {} + | wc -c)
+ count=$((count - 1))
+ printf '%u\t%s\n' "$count" "$dir"
done
exit "${ex:-0}"