Drop no longer needed _compopt_o_filenames().

Use compopt -o filenames directly instead.
This commit is contained in:
Ville Skyttä 2011-04-21 12:33:05 +03:00
parent 6589a0d61b
commit 9f45e81e65
18 changed files with 28 additions and 41 deletions

View File

@ -597,19 +597,6 @@ _quote_readline_by_ref()
} # _quote_readline_by_ref()
# This function turns on "-o filenames" behavior dynamically. It is present
# for bash < 4 reasons. See http://bugs.debian.org/272660#64 for info about
# the bash < 4 compgen hack.
_compopt_o_filenames()
{
# We test for compopt availability first because directly invoking it on
# bash < 4 at this point may cause terminal echo to be turned off for some
# reason, see https://bugzilla.redhat.com/653669 for more info.
type compopt &>/dev/null && compopt -o filenames 2>/dev/null || \
compgen -f /non-existing-dir/ >/dev/null
}
# This function performs file and directory completion. It's better than
# simply using 'compgen -f', because it honours spaces in filenames.
# @param $1 If `-d', complete only on directories. Otherwise filter/pick only
@ -649,7 +636,7 @@ _filedir()
[[ -n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \
toks+=( $( compgen -f -- $quoted ) )
[ ${#toks[@]} -ne 0 ] && _compopt_o_filenames
[ ${#toks[@]} -ne 0 ] && compopt -o filenames 2>/dev/null
COMPREPLY+=( "${toks[@]}" )
} # _filedir()
@ -859,7 +846,7 @@ _tilde() {
local result=0
# Does $1 start with tilde (~) and doesn't contain slash (/)?
if [[ ${1:0:1} == "~" && $1 == ${1//\/} ]]; then
_compopt_o_filenames
compopt -o filenames 2>/dev/null
# Try generate username completions
COMPREPLY=( $( compgen -P '~' -u "${1#\~}" ) )
result=${#COMPREPLY[@]}
@ -1447,7 +1434,7 @@ _cd()
return 0
fi
_compopt_o_filenames
compopt -o filenames
# Use standard dir completion if no CDPATH or parameter starts with /,
# ./ or ../
@ -1544,7 +1531,7 @@ _command_offset()
_get_comp_words_by_ref cur
if [[ $COMP_CWORD -eq 0 ]]; then
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -c -- "$cur" ) )
else
cmd=${COMP_WORDS[0]} compcmd=${COMP_WORDS[0]}
@ -1577,7 +1564,7 @@ _command_offset()
if [[ "$cspec" != @(dir|file)names ]]; then
COMPREPLY=("${COMPREPLY[@]//\\\\:/:}")
else
_compopt_o_filenames
compopt -o filenames
fi
fi
else
@ -1693,7 +1680,7 @@ _filedir_xspec()
}
))
[ ${#toks[@]} -ne 0 ] && _compopt_o_filenames
[ ${#toks[@]} -ne 0 ] && compopt -o filenames
COMPREPLY=( "${toks[@]}" )
}
list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' "$BASH_COMPLETION" | \

View File

@ -34,7 +34,7 @@ _bzip2()
_expand || return 0
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) )
} &&

View File

@ -30,7 +30,7 @@ _cpio()
return 0
;;
--rsh-command)
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -c -- "$cur" ) )
return 0
;;

View File

@ -9,7 +9,7 @@ _gdb()
if [ $cword -eq 1 ]; then
local IFS
_compopt_o_filenames
compopt -o filenames
if [[ "$cur" == */* ]]; then
# compgen -c works as expected if $cur contains any slashes.
IFS=$'\n'

View File

@ -34,7 +34,7 @@ _gzip()
_expand || return 0
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) )
} &&

View File

@ -10,7 +10,7 @@ _kldload()
local moddir=/modules/
[ -d $moddir ] || moddir=/boot/kernel/
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f "$moddir$cur" ) )
COMPREPLY=( ${COMPREPLY[@]#$moddir} )
COMPREPLY=( ${COMPREPLY[@]%.ko} )

View File

@ -49,7 +49,7 @@ _lrzip()
_expand || return 0
local IFS=$'\n'
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) )
} &&

View File

@ -29,7 +29,7 @@ _lzma()
_expand || return 0
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) )
} &&

View File

@ -53,7 +53,7 @@ _lzop()
_expand || return 0
local IFS=$'\n'
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) )
} &&

View File

@ -49,7 +49,7 @@ _mdtool()
return 0
;;
"generate-makefiles")
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -o filenames -G"*.mds" -- "$cur" ) )
if [[ "$prev" == *mds ]]; then
COMPREPLY=( $( compgen -W '--simple-makefiles --s --d:' \

View File

@ -123,7 +123,7 @@ _muttfiledir()
# Match any file in $folder beginning with $cur
# (minus the leading '=' sign).
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) )
COMPREPLY=( ${COMPREPLY[@]#$folder/} )
return 0

View File

@ -40,7 +40,7 @@ _perl()
;;
-I|-x)
local IFS=$'\n'
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -d $optPrefix $optSuffix -- "$cur" ) )
return 0
;;

View File

@ -54,7 +54,7 @@ _postmap()
fi
if [[ "$cur" == *:* ]]; then
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -- "${cur#*:}" ) )
else
local len=${#cur} idx=0 pval
@ -65,7 +65,7 @@ _postmap()
fi
done
if [[ $idx -eq 0 ]]; then
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -- "$cur" ) )
fi
fi

View File

@ -71,7 +71,7 @@ _rpm()
return 0
;;
--pipe)
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -c -- "$cur" ) )
return 0
;;

View File

@ -181,7 +181,7 @@ _ssh()
done
_known_hosts_real -a -F "$configfile" "$cur"
if [ $cword -ne 1 ]; then
_compopt_o_filenames
compopt -o filenames
COMPREPLY+=( $( compgen -c -- "$cur" ) )
fi
fi

View File

@ -92,7 +92,7 @@ _tar()
;;
-F|--info-script|--new-volume-script|--rmt-command|--rsh-command|\
-I|--use-compress-program)
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -c -- "$cur" ) )
return 0
;;

View File

@ -52,7 +52,7 @@ _xz()
_expand || return 0
local IFS=$'\n'
_compopt_o_filenames
compopt -o filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) )
} &&

View File

@ -60,11 +60,11 @@ key combinations.
As a rule of thumb, do not use "complete -o filenames". Doing it makes
it take effect for all completions from the affected function, which
may break things if some completions from the function must not be
escaped as filenames. Instead, use the _compopt_o_filenames function
to turn on "-o filenames" behavior dynamically when returning
completions that need that kind of processing (e.g. file and command
names). The _filedir and _filedir_xspec helpers do this automatically
whenever they return some completions.
escaped as filenames. Instead, use "compopt -o filenames" to turn on
"-o filenames" behavior dynamically when returning completions that
need that kind of processing (e.g. file and command names). The
_filedir and _filedir_xspec helpers do this automatically whenever
they return some completions.
/////////////////////////////////////////
case/esac vs if