diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-31 19:12:21 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-31 20:23:51 +1200 |
commit | f1fc74cdd6fbc4ea632be035cca6239370a6ea55 (patch) | |
tree | 77c6c96f868d6a884b3bfc8557f0967c3f4a387b /bin/cf | |
parent | Split out sls(1) into shell and awk (diff) | |
download | dotfiles-f1fc74cdd6fbc4ea632be035cca6239370a6ea55.tar.gz dotfiles-f1fc74cdd6fbc4ea632be035cca6239370a6ea55.zip |
Change cf(1) to POSIX sh and multi args
Diffstat (limited to 'bin/cf')
-rwxr-xr-x | bin/cf | 47 |
1 files changed, 20 insertions, 27 deletions
@@ -1,27 +1,20 @@ -#!/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" +#!/bin/sh +# Count entries in a given set of directories +ex=0 +for dir in "${@:-.}" ; do + if ! [ -d "$dir" ] ; then + printf >&2 'cf: %s: not a directory\n' "$dir" + ex=1 + continue + fi + c=0 + for ent in "$dir"/* "$dir"/.* ; do + [ -e "$ent" ] || continue + case $ent in + */.|*/..) ;; + *) c=$((c+1)) ;; + esac + done + printf '%u\t%s\n' "$c" "$dir" +done +exit "$ex" |