aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/cf.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-10-21 13:08:09 +1300
committerTom Ryder <tom@sanctum.geek.nz>2015-10-21 13:08:09 +1300
commitdcfc80aaa112498498d93bae3ae0eb2088244c47 (patch)
tree889854ba1c96f1c86465da1bbd5cc87f0c8d4b9f /bash/bashrc.d/cf.bash
parentHandle spaces correctly in completions (diff)
downloaddotfiles-dcfc80aaa112498498d93bae3ae0eb2088244c47.tar.gz
dotfiles-dcfc80aaa112498498d93bae3ae0eb2088244c47.zip
Tidy up completion considerably; no more compgen
* Remove all instances of compgen; for filename completion it's quite broken as it relies on implicit wordsplitting in array context, and doesn't have an option to print with a null delimiter; replaced with manual for/while loops instead * Add IFS= to while/read loops over filenames * Use "dirname/s" instead of "dir/s" variables to avoid keyword collisions and for clarity * Remove some unnecessary variables * Use shorter syntax for loop exit conditions * Move completion options into functions where applicable rather than having them on the completion definition itself
Diffstat (limited to 'bash/bashrc.d/cf.bash')
-rw-r--r--bash/bashrc.d/cf.bash20
1 files changed, 10 insertions, 10 deletions
diff --git a/bash/bashrc.d/cf.bash b/bash/bashrc.d/cf.bash
index be66ecea..4109fb18 100644
--- a/bash/bashrc.d/cf.bash
+++ b/bash/bashrc.d/cf.bash
@@ -1,30 +1,30 @@
# Count files
cf() {
- local dir
+ local dirname
# Specify directory to check
- dir=${1:-$PWD}
+ dirname=${1:-$PWD}
# Error conditions
- if [[ ! -e $dir ]] ; then
+ if [[ ! -e $dirname ]] ; then
printf 'bash: %s: %s does not exist\n' \
- "$FUNCNAME" "$dir" >&2
+ "$FUNCNAME" "$dirname" >&2
return 1
- elif [[ ! -d $dir ]] ; then
+ elif [[ ! -d $dirname ]] ; then
printf 'bash: %s: %s is not a directory\n' \
- "$FUNCNAME" "$dir" >&2
+ "$FUNCNAME" "$dirname" >&2
return 1
- elif [[ ! -r $dir ]] ; then
+ elif [[ ! -r $dirname ]] ; then
printf 'bash: %s: %s is not readable\n' \
- "$FUNCNAME" "$dir" >&2
+ "$FUNCNAME" "$dirname" >&2
return 1
fi
# Count files and print; use a subshell so options are unaffected
(
shopt -s dotglob nullglob
- declare -a files=("$dir"/*)
- printf '%d\t%s\n' "${#files[@]}" "$dir"
+ declare -a files=("$dirname"/*)
+ printf '%d\t%s\n' "${#files[@]}" "$dirname"
)
}
complete -A directory cf