aboutsummaryrefslogtreecommitdiff
path: root/bin/cf
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-11-25 20:49:00 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-11-25 20:49:00 +1300
commita823aa9f193e2d83fe7882363e59a5b06dba13f2 (patch)
treef3381b2a7fd13344a07f424f53145e243005334a /bin/cf
parentLess clumsy method of counting (diff)
downloaddotfiles-a823aa9f193e2d83fe7882363e59a5b06dba13f2.tar.gz
dotfiles-a823aa9f193e2d83fe7882363e59a5b06dba13f2.zip
Centralize cf(1df)/cfr(1df)
They are almost exactly the same script now; there might be a better way to do this
Diffstat (limited to 'bin/cf')
-rwxr-xr-xbin/cf17
1 files changed, 13 insertions, 4 deletions
diff --git a/bin/cf b/bin/cf
index 4a4c7f7f..c844b054 100755
--- a/bin/cf
+++ b/bin/cf
@@ -1,22 +1,31 @@
#!/bin/sh
# Count entries in a given set of directories
-self=cf
# Iterate over remaining non-option arguments (directories); default to current
# directory if none given
for dir in "${@:-.}" ; do
+ # Strip a trailing slash
+ dir=${dir%/}
+
+ # If the path is not absolute or already pre-dotted, tack a ./ to
+ # the front so that find(1) doesn't choke; otherwise juse use it
+ # as-is
+ case $dir in
+ /*|./*) fdir=$dir ;;
+ *) fdir=./$dir ;;
+ esac
+
# Warn if a non-directory was given, flag errors, but continue
if ! [ -d "$dir" ] ; then
- printf >&2 '%s: %s: not a directory\n' \
- "$self" "$dir"
+ printf >&2 'cf: %s: not a directory\n' "$dir"
ex=1
continue
fi
# Count the files
count=$(
- find "$dir" -path "$dir"'/*' -prune -exec printf %.sx {} + |
+ find "$fdir" -path "$fdir"'/*' -prune -exec printf %.sx {} + |
wc -c
)