aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-30 02:29:44 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-30 02:29:44 +1200
commitbcaaf3210bf644ac7bb5cb05d98b0b17aa258c2c (patch)
treec988a6c96adf2358db794940f1f1f125fae96201 /bin
parentAdd install-bin to default install target (diff)
downloaddotfiles-bcaaf3210bf644ac7bb5cb05d98b0b17aa258c2c.tar.gz
dotfiles-bcaaf3210bf644ac7bb5cb05d98b0b17aa258c2c.zip
Change cf() from Bash func to shell script
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cf27
1 files changed, 27 insertions, 0 deletions
diff --git a/bin/cf b/bin/cf
new file mode 100755
index 00000000..d1515a03
--- /dev/null
+++ b/bin/cf
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+
+# Count files
+self=cf
+
+# Specify directory to check, defaults to current dir
+dirname=${1:-"$PWD"}
+
+# Error conditions
+if [[ ! -e $dirname ]] ; then
+ printf '%s: %s does not exist\n' \
+ "$self" "$dirname" >&2
+ exit 1
+elif [[ ! -d $dirname ]] ; then
+ printf '%s: %s is not a directory\n' \
+ "$self" "$dirname" >&2
+ exit 1
+elif [[ ! -r $dirname ]] ; then
+ printf '%s: %s is not readable\n' \
+ "$self" "$dirname" >&2
+ exit 1
+fi
+
+# Count files and print; use dotglob and nullglob so we get an accurate count
+shopt -s dotglob nullglob
+declare -a files=("$dirname"/*)
+printf '%u\t%s\n' "${#files[@]}" "$dirname"