From 1aa894b7ddb505cb8c7209d80c36a1f53c504dcc Mon Sep 17 00:00:00 2001 From: ianmacd <> Date: Thu, 20 Dec 2001 16:12:44 +0000 Subject: [PATCH] avoid use of extra file descriptor and grep in _file_and_dir by using parameter substitutions --- bash_completion | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/bash_completion b/bash_completion index 5ac29197..2139d6b0 100644 --- a/bash_completion +++ b/bash_completion @@ -2,7 +2,7 @@ # # # @@ -1435,26 +1435,25 @@ _file_and_dir() COMPREPLY=( $( eval compgen -f -X "$xspec" $cur ) $( compgen -d $cur ) ) } -# read exclusion compspecs -IFS=$'\n' -exec 3< /etc/bash_completion -while read line <&3 -do - # only parse relevant section - echo $line | grep -q '^# START exclude' && found=1 && read line <&3 - [ -z "$found" ] && continue - echo $line | grep -q '^# FINISH exclude' && break - # leave only names of commands for which to make a compspec - line=${line##*\'} - list=( ${list[@]} $line ) -done -exec 3<&- -IFS=$' \t\n' +list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' \ + /etc/bash_completion | \ + # read exclusion compspecs + ( + while read line + do + line=${line%# START exclude*} + line=${line%# FINISH exclude*} + line=${line##*\'} + list=( ${list[@]} $line ) + done + echo ${list[@]} + ) +) ) # remove previous compspecs eval complete -r ${list[@]} # install new compspecs eval complete -F _file_and_dir -o filenames ${list[@]} -unset line found list[@] +unset list[@] # source user completion file [ -f ~/.bash_completion ] && . ~/.bash_completion