diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-30 02:29:44 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-30 02:29:44 +1200 |
commit | bcaaf3210bf644ac7bb5cb05d98b0b17aa258c2c (patch) | |
tree | c988a6c96adf2358db794940f1f1f125fae96201 /bin | |
parent | Add install-bin to default install target (diff) | |
download | dotfiles-bcaaf3210bf644ac7bb5cb05d98b0b17aa258c2c.tar.gz dotfiles-bcaaf3210bf644ac7bb5cb05d98b0b17aa258c2c.zip |
Change cf() from Bash func to shell script
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cf | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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" |