From ce12911d25cfeee03459833d736f964c2a7bf37a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 2 Dec 2018 12:57:21 +1300 Subject: Rearrange _text_filenames completion a little Use an integer index for adding values. --- bash/bash_completion.d/_text_filenames.bash | 26 ++++++++++++++------------ 1 file 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") } -- cgit v1.2.3