aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-02 12:57:21 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-02 12:57:21 +1300
commitce12911d25cfeee03459833d736f964c2a7bf37a (patch)
treeef63fdaad583dc224f65b1105393be1c00ce4291
parentRemove prompt() completion (diff)
downloaddotfiles-ce12911d25cfeee03459833d736f964c2a7bf37a.tar.gz
dotfiles-ce12911d25cfeee03459833d736f964c2a7bf37a.zip
Rearrange _text_filenames completion a little
Use an integer index for adding values.
-rw-r--r--bash/bash_completion.d/_text_filenames.bash26
1 files changed, 14 insertions, 12 deletions
diff --git a/bash/bash_completion.d/_text_filenames.bash b/bash/bash_completion.d/_text_filenames.bash
index caf05e8d..b6e035ad 100644
--- a/bash/bash_completion.d/_text_filenames.bash
+++ b/bash/bash_completion.d/_text_filenames.bash
@@ -8,24 +8,26 @@
# the thing I want, and I want it to stay fast.
#
_text_filenames() {
- local item
- while IFS= read -r item ; do
+
+ # Iterate through completions produced by subshell
+ local ci comp
+ while IFS= read -r comp ; do
# Exclude blanks
- [[ -n $item ]] || continue
+ [[ -n $comp ]] || continue
# Exclude nonexistent (some sort of error)
- [[ -e $item ]] || continue
+ [[ -e $comp ]] || continue
# Exclude files with block, character, pipe, or socket type
- ! [[ -b $item ]] || continue
- ! [[ -c $item ]] || continue
- ! [[ -p $item ]] || continue
- ! [[ -S $item ]] || continue
+ ! [[ -b $comp ]] || continue
+ ! [[ -c $comp ]] || continue
+ ! [[ -p $comp ]] || continue
+ ! [[ -S $comp ]] || continue
# Accept directories
- if [[ -d $item ]] ; then
- COMPREPLY[${#COMPREPLY[@]}]=$item
+ if [[ -d $comp ]] ; then
+ COMPREPLY[ci++]=$comp
continue
fi
@@ -35,7 +37,7 @@ _text_filenames() {
shopt -s nocasematch 2>/dev/null
# Match against known binary patterns
- case $item in
+ case $comp in
# Archives
(*.7z) ;;
@@ -153,7 +155,7 @@ _text_filenames() {
) || continue
# Complete everything else; some of it will still be binary
- COMPREPLY[${#COMPREPLY[@]}]=$item
+ COMPREPLY[ci++]=$comp
done < <(compgen -A file -- "$2")
}