Remove most "-o filenames" options to "complete".

Turn it on dynamically when needed instead; see doc/styleguide.txt for
a longer explanation.  This fixes many non-filename completions which
had been previously more or less broken due to unwanted
escape-as-filenames behavior.
This commit is contained in:
Ville Skyttä 2010-11-01 19:26:53 +02:00
parent 494c44f5a3
commit 0f450219b6
88 changed files with 160 additions and 189 deletions

View File

@ -34,6 +34,8 @@ bash-completion (2.x)
* Complete known hosts from avahi-browse only if $COMP_KNOWN_HOSTS_WITH_AVAHI * Complete known hosts from avahi-browse only if $COMP_KNOWN_HOSTS_WITH_AVAHI
is non-empty (Alioth: #312691, RedHat: #630326). is non-empty (Alioth: #312691, RedHat: #630326).
* Improve relevance of many user/group completions, depending on context. * Improve relevance of many user/group completions, depending on context.
* Remove most "-o filenames" options to "complete", turn "-o filenames" on
dynamically when needed instead.
[ Freddy Vulto ] [ Freddy Vulto ]
* Added _tilde(), fix ~username completion (Alioth: #312613, Debian: #587095) * Added _tilde(), fix ~username completion (Alioth: #312613, Debian: #587095)

View File

@ -1487,6 +1487,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
COMPREPLY=( $( compgen -c -- "$cur" ) ) COMPREPLY=( $( compgen -c -- "$cur" ) )
else else
cmd=${COMP_WORDS[0]} cmd=${COMP_WORDS[0]}
@ -1525,8 +1526,8 @@ _command_offset()
[ ${#COMPREPLY[@]} -eq 0 ] && _filedir [ ${#COMPREPLY[@]} -eq 0 ] && _filedir
} }
complete -F _command -o filenames aoss command do else eval exec ltrace nice \ complete -F _command aoss command do else eval exec ltrace nice nohup padsp \
nohup padsp then time tsocks vsound xargs then time tsocks vsound xargs
_root_command() _root_command()
{ {
@ -1534,7 +1535,7 @@ _root_command()
local root_command=$1 local root_command=$1
_command $1 $2 $3 _command $1 $2 $3
} }
complete -F _root_command -o filenames fakeroot gksu gksudo kdesudo really sudo complete -F _root_command fakeroot gksu gksudo kdesudo really sudo
# Return true if the completion should be treated as running as root # Return true if the completion should be treated as running as root
_complete_as_root() _complete_as_root()
@ -1574,16 +1575,11 @@ _longopt()
} }
# makeinfo and texi2dvi are defined elsewhere. # makeinfo and texi2dvi are defined elsewhere.
for i in a2ps autoconf automake awk bash bc bison cat colordiff cp csplit \ for i in a2ps autoconf automake awk bash bc bison cat colordiff cp csplit \
curl cut date df diff dir du enscript expand fmt fold gperf gprof grep \ curl cut date df diff dir du enscript env expand fmt fold gperf gprof \
grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod mv nl \ grep grub head indent irb ld ldd less ln ls m4 md5sum mkdir mkfifo mknod \
nm objcopy objdump od paste patch pr ptx readelf rm rmdir sed \ mv netstat nl nm objcopy objdump od paste patch pr ptx readelf rm rmdir \
sha{,1,224,256,384,512}sum shar sort split strip tac tail tee texindex \ sed seq sha{,1,224,256,384,512}sum shar sort split strip tac tail tee \
touch tr unexpand uniq vdir wc wget who; do texindex touch tr uname unexpand uniq units vdir wc wget who; do
have $i && complete -F _longopt -o filenames $i
done
# These commands do not use filenames, so '-o filenames' is not needed.
for i in env netstat seq uname units; do
have $i && complete -F _longopt -o default $i have $i && complete -F _longopt -o default $i
done done
unset i unset i
@ -1636,6 +1632,7 @@ _filedir_xspec()
} }
)) ))
[ ${#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" | \
@ -1657,7 +1654,7 @@ list=( $( sed -ne '/^# START exclude/,/^# FINISH exclude/p' "$BASH_COMPLETION" |
if [ ${#list[@]} -gt 0 ]; then if [ ${#list[@]} -gt 0 ]; then
eval complete -r ${list[@]} eval complete -r ${list[@]}
# install new compspecs # install new compspecs
eval complete -F _filedir_xspec -o filenames "${list[@]}" eval complete -F _filedir_xspec "${list[@]}"
fi fi
unset list unset list

View File

@ -74,7 +74,7 @@ _mock()
_filedir '@(?(no)src.r|s)pm' _filedir '@(?(no)src.r|s)pm'
fi fi
} && } &&
complete -F _mock -o filenames mock complete -F _mock mock
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -216,7 +216,7 @@ _svn()
return 0 return 0
} }
complete -F _svn -o filenames svn complete -F _svn svn
_svnadmin() _svnadmin()
{ {

View File

@ -146,7 +146,7 @@ _yum()
fi fi
} }
} && } &&
complete -F _yum -o filenames yum complete -F _yum yum
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -20,7 +20,7 @@ _repomanage()
_filedir -d _filedir -d
fi fi
} && } &&
complete -F _repomanage -o filenames repomanage complete -F _repomanage repomanage
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -26,13 +26,11 @@ _abook()
case $prev in case $prev in
--informat) --informat)
[ ${BASH_VERSINFO[0]} -ge 4 ] && compopt +o filenames
COMPREPLY=( $( compgen -W "$(abook --formats | \ COMPREPLY=( $( compgen -W "$(abook --formats | \
sed -n -e 's/^\t\([a-z]*\).*/\1/p' -e '/^$/q')" -- "$cur" ) ) sed -n -e 's/^\t\([a-z]*\).*/\1/p' -e '/^$/q')" -- "$cur" ) )
return 0 return 0
;; ;;
--outformat) --outformat)
[ ${BASH_VERSINFO[0]} -ge 4 ] && compopt +o filenames
COMPREPLY=( $( compgen -W "$(abook --formats | \ COMPREPLY=( $( compgen -W "$(abook --formats | \
sed -n -e '/^$/,$s/^\t\([a-z]*\).*/\1/p')" -- "$cur" ) ) sed -n -e '/^$/,$s/^\t\([a-z]*\).*/\1/p')" -- "$cur" ) )
return 0 return 0
@ -53,7 +51,7 @@ _abook()
;; ;;
esac esac
} && } &&
complete -F _abook -o filenames abook complete -F _abook abook
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -58,8 +58,7 @@ _ant()
fi fi
} }
have complete-ant-cmd.pl && \ have complete-ant-cmd.pl && \
complete -C complete-ant-cmd.pl -F _ant -o filenames ant || \ complete -C complete-ant-cmd.pl -F _ant ant || complete -F _ant ant
complete -F _ant -o filenames ant
} }
# Local variables: # Local variables:

View File

@ -71,7 +71,7 @@ _apt_get()
return 0 return 0
} && } &&
complete -F _apt_get -o filenames apt-get complete -F _apt_get apt-get
# Debian apt-cache(8) completion. # Debian apt-cache(8) completion.
# #
@ -146,7 +146,7 @@ _apt_cache()
return 0 return 0
} && } &&
complete -F _apt_cache -o filenames apt-cache complete -F _apt_cache apt-cache
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -55,7 +55,7 @@ _apt_build()
return 0 return 0
} && } &&
complete -F _apt_build -o filenames apt-build complete -F _apt_build apt-build
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -84,7 +84,7 @@ _aspell()
fi fi
} }
complete -F _aspell -o filenames aspell complete -F _aspell aspell
} }
# Local variables: # Local variables:

View File

@ -36,10 +36,11 @@ _bzip2()
_expand || return 0 _expand || return 0
_compopt_o_filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) ) $( compgen -d -- "$cur" ) )
} && } &&
complete -F _bzip2 -o filenames bzip2 pbzip2 complete -F _bzip2 bzip2 pbzip2
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -33,7 +33,7 @@ _configure()
-- "$cur" ) ) -- "$cur" ) )
fi fi
} }
complete -F _configure -o filenames configure complete -F _configure configure
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -47,7 +47,7 @@ _chown()
fi fi
fi fi
} && } &&
complete -F _chown -o filenames chown complete -F _chown chown
# chgrp(1) completion # chgrp(1) completion
@ -91,7 +91,7 @@ _chgrp()
return 0 return 0
} && } &&
complete -F _chgrp -o filenames chgrp complete -F _chgrp chgrp
# id(1) completion # id(1) completion
# #

View File

@ -30,6 +30,7 @@ _cpio()
return 0 return 0
;; ;;
--rsh-command) --rsh-command)
_compopt_o_filenames
COMPREPLY=( $( compgen -c -- "$cur" ) ) COMPREPLY=( $( compgen -c -- "$cur" ) )
return 0 return 0
;; ;;
@ -90,7 +91,7 @@ _cpio()
esac esac
fi fi
} }
complete -F _cpio -o filenames cpio complete -F _cpio cpio
} }
# Local variables: # Local variables:

View File

@ -49,7 +49,7 @@ _crontab()
# do filenames only if we did not have -l, -r, or -e # do filenames only if we did not have -l, -r, or -e
[[ "${COMP_LINE}" == *\ -@(l|r|e)* ]] || _filedir [[ "${COMP_LINE}" == *\ -@(l|r|e)* ]] || _filedir
} && } &&
complete -F _crontab -o filenames crontab complete -F _crontab crontab
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -10,7 +10,7 @@ _cancel()
COMPREPLY=( $( compgen -W "$( lpstat | cut -d' ' -f1 )" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$( lpstat | cut -d' ' -f1 )" -- "$cur" ) )
} && } &&
complete -F _cancel -o filenames cancel complete -F _cancel cancel
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -28,7 +28,7 @@ _dd()
$( compgen -W 'bs cbs conv count ibs if obs of seek skip' \ $( compgen -W 'bs cbs conv count ibs if obs of seek skip' \
-S '=' -- "$cur" ) ) -S '=' -- "$cur" ) )
} && } &&
complete -F _dd -o nospace -o filenames dd complete -F _dd -o nospace dd
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -92,7 +92,7 @@ _dpkg()
} }
complete -F _dpkg -o filenames dpkg dpkg-deb complete -F _dpkg dpkg dpkg-deb
} }
# Debian GNU dpkg-reconfigure(8) completion # Debian GNU dpkg-reconfigure(8) completion

View File

@ -29,7 +29,7 @@ _dselect()
return 0 return 0
} && } &&
complete -F _dselect -o filenames dselect complete -F _dselect dselect
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -27,7 +27,7 @@ _badblocks()
cur=${cur:=/dev/} cur=${cur:=/dev/}
_filedir _filedir
} && } &&
complete -F _badblocks -o filenames badblocks complete -F _badblocks badblocks
have dumpe2fs && have dumpe2fs &&
@ -55,7 +55,7 @@ _dumpe2fs()
cur=${cur:=/dev/} cur=${cur:=/dev/}
_filedir _filedir
} && } &&
complete -F _dumpe2fs -o filenames dumpe2fs complete -F _dumpe2fs dumpe2fs
have e2freefrag && have e2freefrag &&
@ -79,7 +79,7 @@ _e2freefrag()
cur=${cur:=/dev/} cur=${cur:=/dev/}
_filedir _filedir
} && } &&
complete -F _e2freefrag -o filenames e2freefrag complete -F _e2freefrag e2freefrag
have e2label && have e2label &&
@ -94,7 +94,7 @@ _e2label()
_filedir _filedir
fi fi
} && } &&
complete -F _e2label -o filenames e2label complete -F _e2label e2label
have filefrag && have filefrag &&
@ -111,7 +111,7 @@ _filefrag()
_filedir _filedir
} && } &&
complete -F _filefrag -o filenames filefrag complete -F _filefrag filefrag
have tune2fs && have tune2fs &&
@ -169,7 +169,7 @@ _tune2fs()
cur=${cur:=/dev/} cur=${cur:=/dev/}
_filedir _filedir
} && } &&
complete -F _tune2fs -o filenames tune2fs complete -F _tune2fs tune2fs
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -117,7 +117,7 @@ _find()
return 0 return 0
} && } &&
complete -F _find -o filenames find complete -F _find find
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -25,7 +25,7 @@ _fusermount()
_filedir -d _filedir -d
fi fi
} && } &&
complete -F _fusermount -o filenames fusermount complete -F _fusermount fusermount
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -46,9 +46,9 @@ _gcc()
_filedir _filedir
fi fi
} && } &&
complete -o filenames -F _gcc gcc g++ c++ g77 gcj gpc complete -F _gcc gcc g++ c++ g77 gcj gpc
[ $USERLAND = GNU -o $UNAME = Cygwin ] && \ [ $USERLAND = GNU -o $UNAME = Cygwin ] && \
[ -n "${have:-}" ] && complete -o filenames -F _gcc cc [ -n "${have:-}" ] && complete -F _gcc cc
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -10,6 +10,7 @@ _gdb()
if [ $COMP_CWORD -eq 1 ]; then if [ $COMP_CWORD -eq 1 ]; then
local IFS local IFS
_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

@ -66,7 +66,7 @@ _mkisofs()
fi fi
} && } &&
complete -F _mkisofs -o filenames mkisofs genisoimage complete -F _mkisofs mkisofs genisoimage
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -43,7 +43,7 @@ _gkrellm()
fi fi
} && } &&
complete -F _gkrellm -o filenames gkrellm gkrellm2 complete -F _gkrellm gkrellm gkrellm2
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -26,7 +26,7 @@ _gnatmake()
_filedir '@(adb|ads)' _filedir '@(adb|ads)'
fi fi
} && } &&
complete -F _gnatmake -o filenames gnatmake complete -F _gnatmake gnatmake
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -40,10 +40,11 @@ _gzip()
_expand || return 0 _expand || return 0
_compopt_o_filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) ) $( compgen -d -- "$cur" ) )
} && } &&
complete -F _gzip -o filenames gzip pigz complete -F _gzip gzip pigz
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -36,8 +36,6 @@ _iconv()
fi fi
} && } &&
complete -F _iconv -o default iconv complete -F _iconv -o default iconv
# Intentionally not -o filenames here, -f/-t completions may contain slashes
# and -o filenames would break them.
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -24,7 +24,7 @@ _iftop()
COMPREPLY=( $( compgen -W '-h -n -N -p -P -b -B -i -f -F -c -m' \ COMPREPLY=( $( compgen -W '-h -n -N -p -P -b -B -i -f -F -c -m' \
-- "$cur" ) ) -- "$cur" ) )
} && } &&
complete -F _iftop -o filenames iftop complete -F _iftop iftop
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -189,7 +189,7 @@ _convert()
_filedir _filedir
fi fi
} }
complete -F _convert -o filenames convert complete -F _convert convert
_mogrify() _mogrify()
{ {
@ -245,7 +245,7 @@ _mogrify()
_filedir _filedir
fi fi
} }
complete -F _mogrify -o filenames mogrify complete -F _mogrify mogrify
_display() _display()
{ {
@ -285,7 +285,7 @@ _display()
_filedir _filedir
fi fi
} }
complete -F _display -o filenames display complete -F _display display
_animate() _animate()
{ {
@ -319,7 +319,7 @@ _animate()
_filedir _filedir
fi fi
} }
complete -F _animate -o filenames animate complete -F _animate animate
_identify() _identify()
{ {
@ -344,7 +344,7 @@ _identify()
_filedir _filedir
fi fi
} }
complete -F _identify -o filenames identify complete -F _identify identify
_montage() _montage()
{ {
@ -382,7 +382,7 @@ _montage()
_filedir _filedir
fi fi
} }
complete -F _montage -o filenames montage complete -F _montage montage
_composite() _composite()
{ {
@ -417,7 +417,7 @@ _composite()
_filedir _filedir
fi fi
} }
complete -F _composite -o filenames composite complete -F _composite composite
_compare() _compare()
{ {
@ -444,7 +444,7 @@ _compare()
_filedir _filedir
fi fi
} }
complete -F _compare -o filenames compare complete -F _compare compare
_conjure() _conjure()
{ {
@ -464,7 +464,7 @@ _conjure()
_filedir _filedir
fi fi
} }
complete -F _conjure -o filenames conjure complete -F _conjure conjure
_import() _import()
{ {
@ -495,7 +495,7 @@ _import()
_filedir _filedir
fi fi
} }
complete -F _import -o filenames import complete -F _import import
_stream() _stream()
{ {
@ -520,7 +520,7 @@ _stream()
_filedir _filedir
fi fi
} }
complete -F _stream -o filenames stream complete -F _stream stream
} }
# Local variables: # Local variables:

View File

@ -47,7 +47,7 @@ _info()
return 0 return 0
} && } &&
complete -F _info -o filenames info complete -F _info info
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -203,7 +203,7 @@ _ipmitool()
} }
} && } &&
complete -F _ipmitool -o filenames ipmitool complete -F _ipmitool ipmitool
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -46,7 +46,7 @@ _ipv6calc()
return 0 return 0
} && } &&
complete -F _ipv6calc -o filenames ipv6calc complete -F _ipv6calc ipv6calc
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -25,7 +25,7 @@ _jar()
;; ;;
esac esac
} && } &&
complete -F _jar -o filenames jar complete -F _jar jar
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -164,7 +164,7 @@ _java()
fi fi
fi fi
} }
complete -F _java -o filenames java complete -F _java java
} }
have javadoc && have javadoc &&
@ -217,7 +217,7 @@ _javadoc()
_java_packages _java_packages
fi fi
} && } &&
complete -F _javadoc -o filenames javadoc complete -F _javadoc javadoc
have javac && have javac &&
_javac() _javac()
@ -249,7 +249,7 @@ _javac()
_filedir java _filedir java
fi fi
} && } &&
complete -F _javac -o filenames javac complete -F _javac javac
have pack200 && have pack200 &&
_pack200() _pack200()
@ -418,7 +418,7 @@ _jarsigner()
_filedir jar _filedir jar
fi fi
} && } &&
complete -F _jarsigner -o filenames jarsigner complete -F _jarsigner jarsigner
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -44,7 +44,7 @@ _k3b()
_filedir _filedir
fi fi
} && } &&
complete -F _k3b -o filenames k3b complete -F _k3b k3b
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -11,13 +11,14 @@ _kldload()
[ -d $moddir ] || moddir=/boot/kernel/ [ -d $moddir ] || moddir=/boot/kernel/
_get_comp_words_by_ref cur _get_comp_words_by_ref cur
_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} )
return 0 return 0
} }
complete -F _kldload -o filenames kldload complete -F _kldload kldload
_kldunload() _kldunload()
{ {
@ -26,7 +27,7 @@ _kldunload()
COMPREPLY=( $( kldstat | \ COMPREPLY=( $( kldstat | \
sed -ne "s/^.*[ \t]\{1,\}\($cur[a-z_]\{1,\}\).ko$/\1/p" ) ) sed -ne "s/^.*[ \t]\{1,\}\($cur[a-z_]\{1,\}\).ko$/\1/p" ) )
} }
complete -F _kldunload -o filenames kldunload complete -F _kldunload kldunload
} }

View File

@ -28,7 +28,8 @@ _lftp()
'$( cut -f 1 -s ~/.lftp/bookmarks 2>/dev/null )' -- "$cur" ) ) '$( cut -f 1 -s ~/.lftp/bookmarks 2>/dev/null )' -- "$cur" ) )
_known_hosts_real "$cur" _known_hosts_real "$cur"
} && } &&
complete -F _lftp -o filenames lftp complete -F _lftp lftp
have lftpget && have lftpget &&
_lftpget() _lftpget()
{ {

View File

@ -32,7 +32,7 @@ _links()
return 0 return 0
} && } &&
complete -F _links -o filenames links complete -F _links links
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -181,6 +181,6 @@ _lintian_info() {
return 0 return 0
} }
complete -F _lintian -o filenames lintian complete -F _lintian lintian
complete -F _lintian_info -o filenames lintian-info complete -F _lintian_info lintian-info
} }

View File

@ -49,10 +49,11 @@ _lrzip()
_expand || return 0 _expand || return 0
local IFS=$'\n' local IFS=$'\n'
_compopt_o_filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) ) $( compgen -d -- "$cur" ) )
} && } &&
complete -F _lrzip -o filenames lrzip complete -F _lrzip lrzip
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -31,10 +31,11 @@ _lzma()
_expand || return 0 _expand || return 0
_compopt_o_filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) ) $( compgen -d -- "$cur" ) )
} && } &&
complete -F _lzma -o filenames lzma complete -F _lzma lzma
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -54,10 +54,11 @@ _lzop()
_expand || return 0 _expand || return 0
local IFS=$'\n' local IFS=$'\n'
_compopt_o_filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) ) $( compgen -d -- "$cur" ) )
} && } &&
complete -F _lzop -o filenames lzop complete -F _lzop lzop
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -368,7 +368,7 @@ _config_list()
fi fi
} && } &&
complete -F _config_list -o filenames config_list complete -F _config_list config_list
# Try to detect whether this is the mailman "arch" to avoid installing # Try to detect whether this is the mailman "arch" to avoid installing
# it for the coreutils/util-linux-ng one. # it for the coreutils/util-linux-ng one.
@ -416,7 +416,7 @@ _arch()
fi fi
} && } &&
complete -F _arch -o filenames arch complete -F _arch arch
have cleanarch && have cleanarch &&
_cleanarch() _cleanarch()
@ -460,7 +460,7 @@ _inject()
fi fi
} && } &&
complete -F _inject -o filenames inject complete -F _inject inject
have dumpdb && have dumpdb &&
_dumpdb() _dumpdb()
@ -478,7 +478,7 @@ _dumpdb()
fi fi
} && } &&
complete -F _dumpdb -o filenames dumpdb complete -F _dumpdb dumpdb
have check_db && have check_db &&
_check_db() _check_db()

View File

@ -67,7 +67,7 @@ _make()
fi fi
} && } &&
complete -F _make -o filenames make gmake gnumake pmake complete -F _make make gmake gnumake pmake
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -69,7 +69,7 @@ _man()
__ltrim_colon_completions "$cur" __ltrim_colon_completions "$cur"
return 0 return 0
} && } &&
complete -F _man -o filenames man apropos whatis complete -F _man man apropos whatis
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -36,7 +36,7 @@ _mc()
_filedir -d _filedir -d
fi fi
} && } &&
complete -F _mc -o filenames mc complete -F _mc mc
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -73,7 +73,7 @@ _mcrypt()
fi fi
fi fi
} && } &&
complete -o filenames -F _mcrypt mcrypt mdecrypt complete -F _mcrypt mcrypt mdecrypt
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -50,7 +50,7 @@ _insmod()
return 0 return 0
} && } &&
complete -F _insmod -o filenames insmod modprobe modinfo complete -F _insmod insmod modprobe modinfo
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -50,6 +50,7 @@ _mdtool()
return 0 return 0
;; ;;
"generate-makefiles") "generate-makefiles")
_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:' \
@ -74,7 +75,7 @@ _mdtool()
return 0 return 0
} && } &&
complete -F _mdtool -o filenames mdtool complete -F _mdtool mdtool
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -253,7 +253,7 @@ _mplayer()
return 0 return 0
} }
complete -o filenames -F _mplayer mplayer mencoder gmplayer kplayer complete -F _mplayer mplayer mencoder gmplayer kplayer
} }
# Local variables: # Local variables:

View File

@ -120,6 +120,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
COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) ) COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) )
COMPREPLY=( ${COMPREPLY[@]#$folder/} ) COMPREPLY=( ${COMPREPLY[@]#$folder/} )
return 0 return 0
@ -170,7 +171,7 @@ _mutt()
;; ;;
esac esac
} # _mutt() } # _mutt()
complete -F _mutt -o default -o filenames mutt muttng complete -F _mutt -o default mutt muttng
} # have mutt } # have mutt
# Local variables: # Local variables:

View File

@ -60,7 +60,7 @@ _mysqladmin()
kill password old-password ping processlist reload refresh shutdown \ kill password old-password ping processlist reload refresh shutdown \
status start-slave stop-slave variables version' -- "$cur" ) ) status start-slave stop-slave variables version' -- "$cur" ) )
} && } &&
complete -F _mysqladmin -o filenames mysqladmin complete -F _mysqladmin mysqladmin
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -31,6 +31,7 @@ _perl()
case $prev in case $prev in
-I|-x) -I|-x)
local IFS=$'\n' local IFS=$'\n'
_compopt_o_filenames
COMPREPLY=( $( compgen -d $optPrefix $optSuffix -- "$cur" ) ) COMPREPLY=( $( compgen -d $optPrefix $optSuffix -- "$cur" ) )
return 0 return 0
;; ;;
@ -47,7 +48,7 @@ _perl()
_filedir _filedir
fi fi
} }
complete -F _perl -o nospace -o filenames perl complete -F _perl -o nospace perl
complete -C ${BASH_SOURCE[0]%/*}/helpers/perldoc -o nospace -o default perldoc complete -C ${BASH_SOURCE[0]%/*}/helpers/perldoc -o nospace -o default perldoc
} }

View File

@ -29,7 +29,7 @@ _postfix()
COMPREPLY=( $( compgen -W 'check start stop abort flush reload status \ COMPREPLY=( $( compgen -W 'check start stop abort flush reload status \
set-permissions upgrade-configuration' -- "$cur" ) ) set-permissions upgrade-configuration' -- "$cur" ) )
} }
complete -F _postfix -o filenames postfix complete -F _postfix postfix
# postalias(1) and postmap(1) # postalias(1) and postmap(1)
# #
@ -57,6 +57,7 @@ _postmap()
fi fi
if [[ "$cur" == *:* ]]; then if [[ "$cur" == *:* ]]; then
_compopt_o_filenames
COMPREPLY=( $( compgen -f -- "${cur#*:}" ) ) COMPREPLY=( $( compgen -f -- "${cur#*:}" ) )
else else
len=${#cur} len=${#cur}
@ -68,12 +69,13 @@ _postmap()
fi fi
done done
if [[ $idx -eq 0 ]]; then if [[ $idx -eq 0 ]]; then
_compopt_o_filenames
COMPREPLY=( $( compgen -f -- "$cur" ) ) COMPREPLY=( $( compgen -f -- "$cur" ) )
fi fi
fi fi
return 0 return 0
} }
complete -F _postmap -o filenames postmap postalias complete -F _postmap postmap postalias
# postcat(1) # postcat(1)
# #
@ -116,7 +118,7 @@ _postcat()
return 0 return 0
fi fi
} }
complete -F _postcat -o filenames postcat complete -F _postcat postcat
# postconf(1) # postconf(1)
# #
@ -158,7 +160,7 @@ _postconf()
done done
return 0 return 0
} }
complete -F _postconf -o filenames postconf complete -F _postconf postconf
# postsuper(1) # postsuper(1)
# #
@ -219,7 +221,7 @@ _postsuper()
COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- "$cur" ) )
} }
complete -F _postsuper -o filenames postsuper complete -F _postsuper postsuper
} }
# Local variables: # Local variables:

View File

@ -151,7 +151,7 @@ _psql()
_pg_databases _pg_databases
fi fi
} }
complete -F _psql -o filenames psql complete -F _psql psql
} }
# Local variables: # Local variables:

View File

@ -54,7 +54,7 @@ _povray()
;; ;;
esac esac
} && } &&
complete -F _povray -o filenames povray xpovray spovray complete -F _povray povray xpovray spovray
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -45,7 +45,7 @@ _python()
return 0 return 0
} && } &&
complete -F _python -o filenames python complete -F _python python
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -121,7 +121,7 @@ _qemu()
_filedir _filedir
fi fi
} && } &&
complete -F _qemu -o filenames qemu complete -F _qemu qemu
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -32,7 +32,7 @@ _rcs()
# otherwise, default to directories # otherwise, default to directories
[[ ${#COMPREPLY[@]} -eq 0 && $1 == ci ]] && _filedir || _filedir -d [[ ${#COMPREPLY[@]} -eq 0 && $1 == ci ]] && _filedir || _filedir -d
} && } &&
complete -F _rcs -o filenames ci co rlog rcs rcsdiff complete -F _rcs ci co rlog rcs rcsdiff
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -84,7 +84,7 @@ _reportbug()
_filedir _filedir
return 0 return 0
} && } &&
complete -F _reportbug -o filenames reportbug complete -F _reportbug reportbug
have querybts && have querybts &&
_querybts() _querybts()
@ -121,7 +121,7 @@ _querybts()
www.debian.org' -- "$cur" ) \ www.debian.org' -- "$cur" ) \
$( apt-cache pkgnames -- "$cur" 2> /dev/null) ) $( apt-cache pkgnames -- "$cur" 2> /dev/null) )
} && } &&
complete -F _querybts -o filenames querybts complete -F _querybts querybts
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -24,8 +24,6 @@ _rpm_installed_packages()
_rpm_groups() _rpm_groups()
{ {
# TODO: shown completions are wrong but real ones work nevertheless
# http://lists.alioth.debian.org/pipermail/bash-completion-devel/2009-May/001486.html
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig --queryformat \ COMPREPLY=( $( compgen -W "$( rpm -qa $nodig $nosig --queryformat \
'%{group}\n' )" -- "$cur" ) ) '%{group}\n' )" -- "$cur" ) )
@ -101,6 +99,7 @@ _rpm()
return 0 return 0
;; ;;
--pipe) --pipe)
_compopt_o_filenames
COMPREPLY=( $( compgen -c -- "$cur" ) ) COMPREPLY=( $( compgen -c -- "$cur" ) )
return 0 return 0
;; ;;
@ -288,7 +287,7 @@ _rpm()
return 0 return 0
} }
complete -F _rpm -o filenames rpm rpmbuild complete -F _rpm rpm rpmbuild
} }
# Local variables: # Local variables:

View File

@ -20,7 +20,7 @@ _sbcl()
return 0 return 0
} && } &&
complete -F _sbcl -o filenames sbcl sbcl-mt complete -F _sbcl sbcl sbcl-mt
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -30,7 +30,7 @@ _sh()
_filedir sh _filedir sh
} && } &&
complete -F _sh -o filenames sh complete -F _sh sh
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -232,7 +232,7 @@ _newusers()
_filedir _filedir
} && } &&
complete -F _newusers -o filenames newusers complete -F _newusers newusers
have pwck && have pwck &&
_pwck() _pwck()
@ -249,7 +249,7 @@ _pwck()
_filedir _filedir
} && } &&
complete -F _pwck -o filenames pwck complete -F _pwck pwck
have groupadd && have groupadd &&
_groupadd() _groupadd()
@ -390,7 +390,7 @@ _grpck()
_filedir _filedir
} && } &&
complete -F _grpck -o filenames grpck complete -F _grpck grpck
have vipw || have vigr && have vipw || have vigr &&
_vipw() _vipw()

View File

@ -28,7 +28,7 @@ _sqlite3()
_filedir $dbexts _filedir $dbexts
} && } &&
complete -F _sqlite3 -o filenames sqlite3 complete -F _sqlite3 sqlite3
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -184,6 +184,7 @@ _ssh()
done done
_known_hosts_real -a -F "$configfile" "$cur" _known_hosts_real -a -F "$configfile" "$cur"
if [ $COMP_CWORD -ne 1 ]; then if [ $COMP_CWORD -ne 1 ]; then
_compopt_o_filenames
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- "$cur" ) ) COMPREPLY=( "${COMPREPLY[@]}" $( compgen -c -- "$cur" ) )
fi fi
fi fi
@ -415,7 +416,7 @@ _ssh_copy_id()
return 0 return 0
} }
complete -F _ssh_copy_id -o filenames ssh-copy-id complete -F _ssh_copy_id ssh-copy-id
} }
# Local variables: # Local variables:

View File

@ -214,7 +214,7 @@ _svk()
return 0 return 0
} && } &&
complete -F _svk -o filenames svk complete -F _svk svk
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -60,7 +60,7 @@ _tar()
return 0 return 0
} }
[ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar -o dirnames tar || [ -n "${COMP_TAR_INTERNAL_PATHS:-}" ] && complete -F _tar -o dirnames tar ||
complete -F _tar -o filenames tar complete -F _tar tar
} }
# Local variables: # Local variables:

View File

@ -18,7 +18,7 @@ _unace()
fi fi
fi fi
} && } &&
complete -F _unace -o filenames unace complete -F _unace unace
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -21,7 +21,7 @@ _unrar()
fi fi
} && } &&
complete -F _unrar -o filenames unrar complete -F _unrar unrar
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -25,7 +25,7 @@ _wtf()
COMPREPLY=( $( compgen -W "$( cut -f 1 -s $db ) -f" -- "${cur}" ) ) COMPREPLY=( $( compgen -W "$( cut -f 1 -s $db ) -f" -- "${cur}" ) )
} && } &&
complete -F _wtf -o filenames wtf complete -F _wtf wtf
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -44,7 +44,7 @@ _xmllint()
_filedir '@(*ml|htm|svg|xs[dl]|rng|wsdl)' _filedir '@(*ml|htm|svg|xs[dl]|rng|wsdl)'
} && } &&
complete -F _xmllint -o filenames xmllint complete -F _xmllint xmllint
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -28,7 +28,7 @@ _xmlwf()
_filedir '@(*ml|htm|svg)' _filedir '@(*ml|htm|svg)'
} && } &&
complete -F _xmlwf -o filenames xmlwf complete -F _xmlwf xmlwf
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -19,7 +19,7 @@ _xmms()
fi fi
} && } &&
complete -F _xmms -o filenames xmms complete -F _xmms xmms
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -21,7 +21,7 @@ _xmodmap()
_filedir _filedir
} && } &&
complete -F _xmodmap -o filenames xmodmap complete -F _xmodmap xmodmap
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -26,7 +26,7 @@ _xrdb()
_filedir _filedir
} && } &&
complete -F _xrdb -o filenames xrdb complete -F _xrdb xrdb
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -45,7 +45,7 @@ _xsltproc()
_filedir '@(xsl|xslt|xml)' _filedir '@(xsl|xslt|xml)'
fi fi
} && } &&
complete -F _xsltproc -o filenames xsltproc complete -F _xsltproc xsltproc
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -53,10 +53,11 @@ _xz()
_expand || return 0 _expand || return 0
local IFS=$'\n' local IFS=$'\n'
_compopt_o_filenames
COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \ COMPREPLY=( $( compgen -f -X "$xspec" -- "$cur" ) \
$( compgen -d -- "$cur" ) ) $( compgen -d -- "$cur" ) )
} && } &&
complete -F _xz -o filenames xz complete -F _xz xz
# xzdec(1) completion # xzdec(1) completion
# #
@ -90,7 +91,7 @@ _xzdec()
_filedir xz # no lzma support here as of xz 4.999.9beta _filedir xz # no lzma support here as of xz 4.999.9beta
} && } &&
complete -F _xzdec -o filenames xzdec complete -F _xzdec xzdec
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -13,7 +13,7 @@ _yum_arch()
_filedir -d _filedir -d
fi fi
} && } &&
complete -F _yum_arch -o filenames yum-arch complete -F _yum_arch yum-arch
# Local variables: # Local variables:
# mode: shell-script # mode: shell-script

View File

@ -54,6 +54,18 @@ is preferable because anyone, with any keyboard layout, is able to
type it. Backticks aren't always available, without doing strange type it. Backticks aren't always available, without doing strange
key combinations. key combinations.
-o filenames
------------
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.
///////////////////////////////////////// /////////////////////////////////////////
case/esac vs if case/esac vs if
--------------- ---------------

View File

@ -2,7 +2,7 @@ set test "Completion via _filedir_xspec() should be installed"
set cmd "complete -p acroread" set cmd "complete -p acroread"
send "$cmd\r" send "$cmd\r"
set expected "^$cmd\r\ncomplete -o filenames -F _filedir_xspec acroread\r\n/@$" set expected "^$cmd\r\ncomplete -F _filedir_xspec acroread\r\n/@$"
expect { expect {
-re $expected { pass "$test" } -re $expected { pass "$test" }
-re /@ { fail "$test at prompt" } -re /@ { fail "$test at prompt" }

View File

@ -40,8 +40,7 @@ if {!$failed_find_unique_completion} {
assert_complete $fulluser:$fullgroup "chown $fulluser:$partgroup" assert_complete $fulluser:$fullgroup "chown $fulluser:$partgroup"
sync_after_int sync_after_int
# One slash should work correctly (doubled here for tcl). assert_complete "dot.user:$fullgroup" "chown dot.user:$partgroup"
assert_complete $fulluser\\:$fullgroup "chown $fulluser\\:$partgroup"
sync_after_int sync_after_int
foreach prefix { foreach prefix {

View File

@ -17,33 +17,8 @@ assert_complete_any "screen -"
sync_after_int sync_after_int
set test "-c should complete files/dirs" assert_complete {bar "bar bar.d/" foo foo.d/} \
set dir fixtures/shared/default "screen -c fixtures/shared/default/" "-c should complete files/dirs"
set prompt "/$dir/@"
assert_bash_exec "cd $dir" "" $prompt
set cmd "screen -c "
set expected {bar {bar bar.d} foo {foo.d}}
send "$cmd\t"
expect -ex "$cmd"
expect {
-re "\r\nbar\\s+bar bar.d/\\s+foo\\s+foo.d/" { pass "$test" }
# Directories might not be suffixed with a slash (/). This is because
# _filedir only works if `-o filenames' is in effect, which isn't the
# case for `screen' on bash-3, so an expected failure (xfail)
-re "\r\nbar\\s+bar bar.d\\s+foo\\s+foo.d" {
if {[lindex $::BASH_VERSINFO 0] < 4} {xfail "$test"} {fail "$test"}
}
-re "\r\nbar\\s+bar\\\\ bar.d/\\s+foo\\s+foo.d/" {
# On bash-3, the space in `bar bar.d' is escaped with a backslash
# as a side-effect of emulating `-o filenames'.
if {[lindex $::BASH_VERSINFO 0] <= 3} {pass "$test"} {fail "$test"}
}
-re $prompt { unresolved "$test at prompt" }
default { unresolved "$test" }
}
sync_after_int $prompt
assert_bash_exec {cd "$TESTDIR"}
sync_after_int sync_after_int

View File

@ -55,21 +55,10 @@ assert_complete_dir $expected "sftp -F spaced\\ \\ conf " $dir
sync_after_int sync_after_int
set test "-F should complete filename"
set dir fixtures/sftp set dir fixtures/sftp
set prompt "/$dir/@" set prompt "/$dir/@"
assert_bash_exec "cd $dir" "" $prompt assert_bash_exec "cd $dir" "" $prompt
set cmd "sftp -Fsp" assert_complete "-Fspaced\\ \\ conf" "sftp -Fsp" "-F should complete filename"
send "$cmd\t"
expect -ex "$cmd"
expect {
-ex "aced\\ \\ conf" { pass "$test" }
# _filedir works only if `-o filenames' is in effect, which isn't the
# case for `sftp'
-re "aced conf" { xfail "$test" }
-re $prompt { unresolved "$test at prompt" }
default { unresolved "$test" }
}
sync_after_int $prompt sync_after_int $prompt
assert_bash_exec {cd "$TESTDIR"} assert_bash_exec {cd "$TESTDIR"}

View File

@ -72,22 +72,9 @@ set test "-F should complete filename"
set dir fixtures/ssh set dir fixtures/ssh
set prompt "/$dir/@" set prompt "/$dir/@"
assert_bash_exec "cd $dir" "" $prompt assert_bash_exec "cd $dir" "" $prompt
set cmd "ssh -Fsp" assert_complete "-Fspaced\\ \\ conf" "ssh -Fsp" "-F should complete filename"
send "$cmd\t"
expect -ex "$cmd"
expect {
-ex "aced\\ \\ conf" { pass "$test" }
# _filedir works only if `-o filenames' is in effect, which isn't the
# case for `ssh'
-re "aced conf" { xfail "$test" }
-re $prompt { unresolved "$test at prompt" }
default { unresolved "$test" }
}
sync_after_int $prompt sync_after_int $prompt
assert_bash_exec {cd "$TESTDIR"} assert_bash_exec {cd "$TESTDIR"}
sync_after_int
teardown teardown