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() } # _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 # This function performs file and directory completion. It's better than
# simply using 'compgen -f', because it honours spaces in filenames. # simply using 'compgen -f', because it honours spaces in filenames.
# @param $1 If `-d', complete only on directories. Otherwise filter/pick only # @param $1 If `-d', complete only on directories. Otherwise filter/pick only
@ -649,7 +636,7 @@ _filedir()
[[ -n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \ [[ -n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \
toks+=( $( compgen -f -- $quoted ) ) toks+=( $( compgen -f -- $quoted ) )
[ ${#toks[@]} -ne 0 ] && _compopt_o_filenames [ ${#toks[@]} -ne 0 ] && compopt -o filenames 2>/dev/null
COMPREPLY+=( "${toks[@]}" ) COMPREPLY+=( "${toks[@]}" )
} # _filedir() } # _filedir()
@ -859,7 +846,7 @@ _tilde() {
local result=0 local result=0
# Does $1 start with tilde (~) and doesn't contain slash (/)? # Does $1 start with tilde (~) and doesn't contain slash (/)?
if [[ ${1:0:1} == "~" && $1 == ${1//\/} ]]; then if [[ ${1:0:1} == "~" && $1 == ${1//\/} ]]; then
_compopt_o_filenames compopt -o filenames 2>/dev/null
# Try generate username completions # Try generate username completions
COMPREPLY=( $( compgen -P '~' -u "${1#\~}" ) ) COMPREPLY=( $( compgen -P '~' -u "${1#\~}" ) )
result=${#COMPREPLY[@]} result=${#COMPREPLY[@]}
@ -1447,7 +1434,7 @@ _cd()
return 0 return 0
fi fi
_compopt_o_filenames compopt -o filenames
# Use standard dir completion if no CDPATH or parameter starts with /, # Use standard dir completion if no CDPATH or parameter starts with /,
# ./ or ../ # ./ or ../
@ -1544,7 +1531,7 @@ _command_offset()
_get_comp_words_by_ref cur _get_comp_words_by_ref cur
if [[ $COMP_CWORD -eq 0 ]]; then if [[ $COMP_CWORD -eq 0 ]]; then
_compopt_o_filenames compopt -o filenames
COMPREPLY=( $( compgen -c -- "$cur" ) ) COMPREPLY=( $( compgen -c -- "$cur" ) )
else else
cmd=${COMP_WORDS[0]} compcmd=${COMP_WORDS[0]} cmd=${COMP_WORDS[0]} compcmd=${COMP_WORDS[0]}
@ -1577,7 +1564,7 @@ _command_offset()
if [[ "$cspec" != @(dir|file)names ]]; then if [[ "$cspec" != @(dir|file)names ]]; then
COMPREPLY=("${COMPREPLY[@]//\\\\:/:}") COMPREPLY=("${COMPREPLY[@]//\\\\:/:}")
else else
_compopt_o_filenames compopt -o filenames
fi fi
fi fi
else else
@ -1693,7 +1680,7 @@ _filedir_xspec()
} }
)) ))
[ ${#toks[@]} -ne 0 ] && _compopt_o_filenames [ ${#toks[@]} -ne 0 ] && compopt -o filenames
COMPREPLY=( "${toks[@]}" ) COMPREPLY=( "${toks[@]}" )
} }
list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' "$BASH_COMPLETION" | \ list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' "$BASH_COMPLETION" | \

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -52,7 +52,7 @@ _xz()
_expand || return 0 _expand || return 0
local IFS=$'\n' local IFS=$'\n'
_compopt_o_filenames compopt -o filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$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 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 it take effect for all completions from the affected function, which
may break things if some completions from the function must not be may break things if some completions from the function must not be
escaped as filenames. Instead, use the _compopt_o_filenames function escaped as filenames. Instead, use "compopt -o filenames" to turn on
to turn on "-o filenames" behavior dynamically when returning "-o filenames" behavior dynamically when returning completions that
completions that need that kind of processing (e.g. file and command need that kind of processing (e.g. file and command names). The
names). The _filedir and _filedir_xspec helpers do this automatically _filedir and _filedir_xspec helpers do this automatically whenever
whenever they return some completions. they return some completions.
///////////////////////////////////////// /////////////////////////////////////////
case/esac vs if case/esac vs if