Drop support for bash < 4.1, clean up no longer needed low hanging cruft.

This commit is contained in:
Ville Skyttä 2011-04-21 12:20:59 +03:00
parent 59e189e636
commit 6589a0d61b
15 changed files with 129 additions and 382 deletions

8
README
View File

@ -12,7 +12,7 @@ if [ -f /etc/bash_completion ]; then
. /etc/bash_completion . /etc/bash_completion
fi fi
(if you happen to have *only* bash >= 3.2 installed, see further if not) (if you happen to have *only* bash >= 4.1 installed, see further if not)
If you don't have the package readily available for your distribution, or If you don't have the package readily available for your distribution, or
you simply don't want to use one, you can install bash completion using the you simply don't want to use one, you can install bash completion using the
@ -291,12 +291,10 @@ guidelines in mind:
start interpreters. Use lightweight programs such as grep(1), awk(1) start interpreters. Use lightweight programs such as grep(1), awk(1)
and sed(1). and sed(1).
- Use the full power of bash >= 3.2. We no longer support earlier bash - Use the full power of bash >= 4.1. We no longer support earlier bash
versions, so you may as well use all the features of that version of versions, so you may as well use all the features of that version of
bash to optimise your code. However, be careful when using features bash to optimise your code. However, be careful when using features
added since bash 3.2, since not everyone will be able to use them. Be added since bash 4.1, since not everyone will be able to use them.
ESPECIALLY careful of using features exclusive to 4.x, as many people
are still using 3.x.
For example, extended globs often enable you to avoid the use of For example, extended globs often enable you to avoid the use of
external programs, which are expensive to fork and execute, so do external programs, which are expensive to fork and execute, so do

2
TODO
View File

@ -2,7 +2,7 @@ bash completion needs to be rewritten from the ground up.
--------------------------------------------------------- ---------------------------------------------------------
bash completion really needs to be rewritten from the ground up, using all of bash completion really needs to be rewritten from the ground up, using all of
the features available in bash 3.2+ and without regard for compatibility with the features available in bash 4.1+ and without regard for compatibility with
earlier versions. earlier versions.
At that time, it should be split into multiple files for easier source At that time, it should be split into multiple files for easier source

View File

@ -1,5 +1,5 @@
# #
# bash_completion - programmable completion functions for bash 3.2+ # bash_completion - programmable completion functions for bash 4.1+
# #
# Copyright © 2006-2008, Ian Macdonald <ian@caliban.org> # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
# © 2009-2011, Bash Completion Maintainers # © 2009-2011, Bash Completion Maintainers
@ -337,8 +337,7 @@ __reassemble_comp_words_by_ref() {
# @param $1 exclude Characters out of $COMP_WORDBREAKS which should NOT be # @param $1 exclude Characters out of $COMP_WORDBREAKS which should NOT be
# considered word breaks. This is useful for things like scp where # considered word breaks. This is useful for things like scp where
# we want to return host:path and not only path, so we would pass the # we want to return host:path and not only path, so we would pass the
# colon (:) as $1 in this case. Bash-3 doesn't do word splitting, so this # colon (:) as $1 in this case.
# ensures we get the same word on both bash-3 and bash-4.
# @param $2 words Name of variable to return words to # @param $2 words Name of variable to return words to
# @param $3 cword Name of variable to return cword to # @param $3 cword Name of variable to return cword to
# @param $4 cur Name of variable to return current word to complete to # @param $4 cur Name of variable to return current word to complete to
@ -408,9 +407,7 @@ __get_cword_at_cursor_by_ref() {
# -n EXCLUDE Characters out of $COMP_WORDBREAKS which should NOT be # -n EXCLUDE Characters out of $COMP_WORDBREAKS which should NOT be
# considered word breaks. This is useful for things like scp # considered word breaks. This is useful for things like scp
# where we want to return host:path and not only path, so we # where we want to return host:path and not only path, so we
# would pass the colon (:) as -n option in this case. Bash-3 # would pass the colon (:) as -n option in this case.
# doesn't do word splitting, so this ensures we get the same
# word on both bash-3 and bash-4.
# -c VARNAME Return cur via $VARNAME # -c VARNAME Return cur via $VARNAME
# -p VARNAME Return prev via $VARNAME # -p VARNAME Return prev via $VARNAME
# -w VARNAME Return words via $VARNAME # -w VARNAME Return words via $VARNAME
@ -468,8 +465,7 @@ _get_comp_words_by_ref()
# @param $1 string Characters out of $COMP_WORDBREAKS which should NOT be # @param $1 string Characters out of $COMP_WORDBREAKS which should NOT be
# considered word breaks. This is useful for things like scp where # considered word breaks. This is useful for things like scp where
# we want to return host:path and not only path, so we would pass the # we want to return host:path and not only path, so we would pass the
# colon (:) as $1 in this case. Bash-3 doesn't do word splitting, so this # colon (:) as $1 in this case.
# ensures we get the same word on both bash-3 and bash-4.
# @param $2 integer Index number of word to return, negatively offset to the # @param $2 integer Index number of word to return, negatively offset to the
# current word (default is 0, previous is 1), respecting the exclusions # current word (default is 0, previous is 1), respecting the exclusions
# given at $1. For example, `_get_cword "=:" 1' returns the word left of # given at $1. For example, `_get_cword "=:" 1' returns the word left of
@ -542,7 +538,7 @@ _get_pword()
# If the word-to-complete contains a colon (:), left-trim COMPREPLY items with # If the word-to-complete contains a colon (:), left-trim COMPREPLY items with
# word-to-complete. # word-to-complete.
# On bash-3, and bash-4 with a colon in COMP_WORDBREAKS, words containing # With a colon in COMP_WORDBREAKS, words containing
# colons are always completed as entire words if the word to complete contains # colons are always completed as entire words if the word to complete contains
# a colon. This function fixes this, by removing the colon-containing-prefix # a colon. This function fixes this, by removing the colon-containing-prefix
# from COMPREPLY items. # from COMPREPLY items.
@ -558,15 +554,7 @@ _get_pword()
# @modifies global array $COMPREPLY # @modifies global array $COMPREPLY
# #
__ltrim_colon_completions() { __ltrim_colon_completions() {
# If word-to-complete contains a colon, if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
# and bash-version < 4,
# or bash-version >= 4 and COMP_WORDBREAKS contains a colon
if [[
"$1" == *:* && (
${BASH_VERSINFO[0]} -lt 4 ||
(${BASH_VERSINFO[0]} -ge 4 && "$COMP_WORDBREAKS" == *:*)
)
]]; then
# Remove colon-word prefix from COMPREPLY items # Remove colon-word prefix from COMPREPLY items
local colon_word=${1%${1##*:}} local colon_word=${1%${1##*:}}
local i=${#COMPREPLY[*]} local i=${#COMPREPLY[*]}
@ -584,20 +572,8 @@ __ltrim_colon_completions() {
# $ ls "a'b/" # $ ls "a'b/"
# c # c
# $ compgen -f "a'b/" # Wrong, doesn't return output # $ compgen -f "a'b/" # Wrong, doesn't return output
# $ compgen -f "a\'b/" # Good (bash-4) # $ compgen -f "a\'b/" # Good
# a\'b/c # a\'b/c
# $ compgen -f "a\\\\\'b/" # Good (bash-3)
# a\'b/c
#
# On bash-3, special characters need to be escaped extra. This is
# unless the first character is a single quote ('). If the single
# quote appears further down the string, bash default completion also
# fails, e.g.:
#
# $ ls 'a&b/'
# f
# $ foo 'a&b/<TAB> # Becomes: foo 'a&b/f'
# $ foo a'&b/<TAB> # Nothing happens
# #
# See also: # See also:
# - http://lists.gnu.org/archive/html/bug-bash/2009-03/msg00155.html # - http://lists.gnu.org/archive/html/bug-bash/2009-03/msg00155.html
@ -608,17 +584,8 @@ __ltrim_colon_completions() {
_quote_readline_by_ref() _quote_readline_by_ref()
{ {
if [[ ${1:0:1} == "'" ]]; then if [[ ${1:0:1} == "'" ]]; then
if [[ ${BASH_VERSINFO[0]} -ge 4 ]]; then # Leave out first character
# Leave out first character printf -v $2 %s "${1:1}"
printf -v $2 %s "${1:1}"
else
# Quote word, leaving out first character
printf -v $2 %q "${1:1}"
# Double-quote word (bash-3)
printf -v $2 %q ${!2}
fi
elif [[ ${BASH_VERSINFO[0]} -le 3 && ${1:0:1} == '"' ]]; then
printf -v $2 %q "${1:1}"
else else
printf -v $2 %q "$1" printf -v $2 %q "$1"
fi fi
@ -674,9 +641,7 @@ _filedir()
if [[ "$1" != -d ]]; then if [[ "$1" != -d ]]; then
# Munge xspec to contain uppercase version too # Munge xspec to contain uppercase version too
[[ ${BASH_VERSINFO[0]} -ge 4 ]] && \ xspec=${1:+"!*.@($1|${1^^})"}
xspec=${1:+"!*.@($1|${1^^})"} || \
xspec=${1:+"!*.@($1|$(printf %s $1 | tr '[:lower:]' '[:upper:]'))"}
toks+=( $( compgen -f -X "$xspec" -- $quoted ) ) toks+=( $( compgen -f -X "$xspec" -- $quoted ) )
fi fi
@ -1718,9 +1683,7 @@ _filedir_xspec()
xspec=${xspec#!} xspec=${xspec#!}
matchop=@ matchop=@
fi fi
[[ ${BASH_VERSINFO[0]} -ge 4 ]] && \ xspec="$matchop($xspec|${xspec^^})"
xspec="$matchop($xspec|${xspec^^})" || \
xspec="$matchop($xspec|$(printf %s $xspec | tr '[:lower:]' '[:upper:]'))"
toks+=( $( toks+=( $(
eval compgen -f -X "!$xspec" -- "\$(quote_readline "\$cur")" | { eval compgen -f -X "!$xspec" -- "\$(quote_readline "\$cur")" | {

View File

@ -3,7 +3,7 @@
# Check for recent enough version of bash. # Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 3 ] || [ $bmajor -eq 3 -a $bminor -ge 2 ]; then if [ $bmajor -gt 4 ] || [ $bmajor -eq 4 -a $bminor -ge 1 ]; then
if shopt -q progcomp && [ -r @sysconfdir@/bash_completion ]; then if shopt -q progcomp && [ -r @sysconfdir@/bash_completion ]; then
# Source completion code. # Source completion code.
. @sysconfdir@/bash_completion . @sysconfdir@/bash_completion

View File

@ -7,9 +7,8 @@ _abook()
local cur prev words cword local cur prev words cword
_init_completion || return _init_completion || return
# abook only takes options, tabbing after command name adds a single # abook only takes options, tabbing after command name adds a single dash
# dash (bash4) [[ $cword -eq 1 && -z "$cur" ]] &&
[[ ${BASH_VERSINFO[0]} -ge 4 && $cword -eq 1 && -z "$cur" ]] &&
{ {
compopt -o nospace compopt -o nospace
COMPREPLY=( "-" ) COMPREPLY=( "-" )

View File

@ -94,23 +94,13 @@ _xvnc4viewer()
ZlibLevel \ ZlibLevel \
) )
[[ "$cur" == --* ]] && dash=-- || dash=- [[ "$cur" == --* ]] && dash=-- || dash=-
# Is a `nocasematch' variable available (bash > v3.1)?
if shopt nocasematch 2> /dev/null | command grep -q ^nocasematch; then local option oldNoCaseMatch=$(shopt -p nocasematch)
# Variable `nocasematch' is available shopt -s nocasematch
# Use vncviewer camelcase options COMPREPLY=( $( for option in "${options[@]}"; do
local option oldNoCaseMatch=$(shopt -p nocasematch)
shopt -s nocasematch
COMPREPLY=( $( for option in "${options[@]}"; do
[[ $dash$option == "$cur"* ]] && printf '%s\n' $dash$option [[ $dash$option == "$cur"* ]] && printf '%s\n' $dash$option
done ) ) done ) )
eval "$oldNoCaseMatch" 2> /dev/null eval "$oldNoCaseMatch" 2>/dev/null
else
# Variable 'nocasematch' isn't available;
# Convert completions to lowercase
COMPREPLY=( $( compgen -W \
"$( tr [:upper:] [:lower:] <<<${options[@]/#/$dash} )" \
-- "$( tr [:upper:] [:lower:] <<<"$cur" )" ) )
fi
else else
_known_hosts_real "$cur" _known_hosts_real "$cur"
fi fi

View File

@ -22,9 +22,7 @@ _wtf()
done done
[ -z $db ] && db=${ACRONYMDB:-/usr/share/misc/acronyms*} [ -z $db ] && db=${ACRONYMDB:-/usr/share/misc/acronyms*}
[ ${BASH_VERSINFO[0]} -ge 4 ] && cur="${cur^^}" COMPREPLY=( $( compgen -W "$( cut -f 1 -s $db ) -f" -- "${cur^^}" ) )
COMPREPLY=( $( compgen -W "$( cut -f 1 -s $db ) -f" -- "${cur}" ) )
} && } &&
complete -F _wtf wtf complete -F _wtf wtf

View File

@ -184,11 +184,6 @@ LOG=/tmp/bash-completion.log~
# Retrieve latest sources # Retrieve latest sources
git pull git pull
# Run tests on bash-3
./runUnit > $LOG || cat $LOG
./runCompletion > $LOG || cat $LOG
# Run tests on bash-4 # Run tests on bash-4
./runUnit --outdir log/bash-4 --tool_exec /opt/bash-4.0/bin/bash > $LOG || cat $LOG ./runUnit --outdir log/bash-4 --tool_exec /opt/bash-4.0/bin/bash > $LOG || cat $LOG

View File

@ -104,11 +104,8 @@ if {[match_items [lsort -unique $expected] -bash-sort]} {
expect { expect {
-re /@ { pass "$test" } -re /@ { pass "$test" }
-re eof { unresolved "eof" } -re eof { unresolved "eof" }
default { fail "$test" }
} }
} else {
# Expected failure (known bug) because of bash-4 bug in quoted words:
# http://www.mail-archive.com/bug-bash@gnu.org/msg06095.html
if {[lindex $::BASH_VERSINFO 0] >= 4} {xfail "$test"} {fail "$test"}
} }
sync_after_int sync_after_int
assert_bash_exec {cd "$TESTDIR"} assert_bash_exec {cd "$TESTDIR"}

View File

@ -435,13 +435,9 @@ proc _ltrim_colon_completions {cmd items dword} {
set cur [lindex $words $index] set cur [lindex $words $index]
} }
# If word-to-complete contains a colon, # If word-to-complete contains a colon,
# and bash-version < 4, # and COMP_WORDBREAKS contains a colon
# or bash-version >= 4 and COMP_WORDBREAKS contains a colon
if { if {
[string first : $cur] > -1 && ( [string first : $cur] > -1 && [string first ":" $::COMP_WORDBREAKS] > -1
[lindex $::BASH_VERSINFO 0] < 4 ||
([lindex $::BASH_VERSINFO 0] >= 4 && [string first ":" $::COMP_WORDBREAKS] > -1)
)
} { } {
set dword_out $cur set dword_out $cur
for {set i 0} {$i < [llength $items_out]} {incr i} { for {set i 0} {$i < [llength $items_out]} {incr i} {
@ -987,29 +983,17 @@ proc start_bash {} {
set env(SRCDIRABS) $::srcdirabs set env(SRCDIRABS) $::srcdirabs
exp_spawn $TOOL_EXECUTABLE --rcfile $::srcdir/config/bashrc exp_spawn $TOOL_EXECUTABLE --rcfile $::srcdir/config/bashrc
assert_bash_exec {} "$TOOL_EXECUTABLE --rcfile $::srcdir/config/bashrc" assert_bash_exec {} "$TOOL_EXECUTABLE --rcfile $::srcdir/config/bashrc"
# Bash < 3.2.41 has a bug where 'history' disappears from SHELLOPTS
# whenever a shopt setting is sourced or eval'ed. Disabling 'history'
# makes it not show in tests "Environment should not be modified"
# for bash < 3.2.41.
# -- FVu, Tue Sep 15 22:52:00 CEST 2009
assert_bash_exec {is_bash_version_minimal 3 2 41 || set +o history}
} }
# Redirect xtrace output to a file. # Redirect xtrace output to a file.
# #
# 'set -x' can be very useful for debugging but by default it writes to # 'set -x' can be very useful for debugging but by default it writes to
# stderr. Bash 4.1 has a feature to redirect this output to a random FD. # stderr.
# #
# This function uses file descriptor 6. This will break if any completion # This function uses file descriptor 6. This will break if any completion
# tries to use the same descriptor. # tries to use the same descriptor.
proc init_bash_xtrace {{fname xtrace.log}} { proc init_bash_xtrace {{fname xtrace.log}} {
global BASH_VERSINFO
if {([lindex $BASH_VERSINFO 0] == 4 && [lindex $BASH_VERSINFO 1] < 1) ||
[lindex $BASH_VERSINFO 0] < 4} {
note "BASH_XTRACEFD not available in this version; no xtrace.log"
return
}
verbose "Enabling bash xtrace output to '$fname'" verbose "Enabling bash xtrace output to '$fname'"
assert_bash_exec "exec 6>'$fname'" assert_bash_exec "exec 6>'$fname'"
assert_bash_exec "BASH_XTRACEFD=6" assert_bash_exec "BASH_XTRACEFD=6"

View File

@ -4,9 +4,7 @@
# @param $1 Char to add to $COMP_WORDBREAKS # @param $1 Char to add to $COMP_WORDBREAKS
# @see remove_comp_wordbreak_char() # @see remove_comp_wordbreak_char()
add_comp_wordbreak_char() { add_comp_wordbreak_char() {
if [ ${BASH_VERSINFO[0]} -ge 4 ]; then [[ "${COMP_WORDBREAKS//[^$1]}" ]] || COMP_WORDBREAKS+=$1
[[ "${COMP_WORDBREAKS//[^$1]}" ]] || COMP_WORDBREAKS=$COMP_WORDBREAKS$1
fi
} # add_comp_wordbreak_char() } # add_comp_wordbreak_char()
@ -60,9 +58,7 @@ is_bash_version_minimal() {
# @param $1 Char to remove from $COMP_WORDBREAKS # @param $1 Char to remove from $COMP_WORDBREAKS
# @see add_comp_wordbreak_char() # @see add_comp_wordbreak_char()
remove_comp_wordbreak_char() { remove_comp_wordbreak_char() {
if [ ${BASH_VERSINFO[0]} -ge 4 ]; then COMP_WORDBREAKS=${COMP_WORDBREAKS//$1}
COMP_WORDBREAKS=${COMP_WORDBREAKS//$1}
fi
} # remove_comp_wordbreak_char() } # remove_comp_wordbreak_char()

View File

@ -124,120 +124,108 @@ foreach name {f f2} {
sync_after_int sync_after_int
# NOTE: Bash versions 4.0.0 up to 4.0.34 contain a bug when completing quoted set cmd "$name 'ab/"
# words, so tests below aren't executed for these bash versions. assert_complete_dir {e'} $cmd "$::srcdir/fixtures/_filedir"
if {! (
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 && sync_after_int
[lindex $::BASH_VERSINFO 2] < 35
)} {
set cmd "$name 'ab/" set cmd "$name 'a b/"
assert_complete_dir {e'} $cmd "$::srcdir/fixtures/_filedir" assert_complete_dir {i'} $cmd "$::srcdir/fixtures/_filedir"
sync_after_int
set cmd "$name 'a\"b/"; #"
assert_complete_dir {d'} $cmd "$::srcdir/fixtures/_filedir"
sync_after_int
set cmd "$name 'a\$b/"
assert_complete_dir {h'} $cmd "$::srcdir/fixtures/_filedir"
sync_after_int
# Execute these tests only when not running on Cygwin/Windows, because
# directories containing `*' or `\' aren't allowed on Cygwin/Windows
if {! [is_cygwin]} {
set cmd "$name '$TESTDIR/tmp/a\\b/"
assert_complete_dir {g'} $cmd "$TESTDIR/tmp"
sync_after_int sync_after_int
}
set cmd "$name 'a b/" set cmd "$name 'a&b/"
assert_complete_dir {i'} $cmd "$::srcdir/fixtures/_filedir" assert_complete_dir {f'} $cmd "$::srcdir/fixtures/_filedir"
sync_after_int sync_after_int
set cmd "$name 'a\"b/"; #" set cmd "$name \"ab/"; #"
assert_complete_dir {d'} $cmd "$::srcdir/fixtures/_filedir" assert_complete_dir {e"} $cmd "$::srcdir/fixtures/_filedir"; #"
sync_after_int sync_after_int
set cmd "$name 'a\$b/" set cmd "$name \"a b/"; #"
if {[lindex $::BASH_VERSINFO 0] == 4} { assert_complete_dir {i"} $cmd "$::srcdir/fixtures/_filedir"; #"
assert_complete_dir {h'} $cmd "$::srcdir/fixtures/_filedir"
} else {
assert_complete_dir "\b\b\b\b$::srcdirabs/fixtures/_filedir/a\$b/h'" $cmd "$::srcdir/fixtures/_filedir"
}
sync_after_int sync_after_int
# Execute these tests only when not running on Cygwin/Windows, because set cmd "$name \"a'b/"; #"
# directories containing `*' or `\' aren't allowed on Cygwin/Windows assert_complete_dir {c"} $cmd "$::srcdir/fixtures/_filedir"; #"
if {! [is_cygwin]} {
set cmd "$name '$TESTDIR/tmp/a\\b/"
assert_complete_dir {g'} $cmd "$TESTDIR/tmp"
sync_after_int sync_after_int
}
set cmd "$name 'a&b/" set cmd "$name \"a\\\"b/"; #"
assert_complete_dir {f'} $cmd "$::srcdir/fixtures/_filedir" assert_complete_dir {d"} $cmd "$::srcdir/fixtures/_filedir"; #"
sync_after_int sync_after_int
set cmd "$name \"ab/"; #" set cmd "$name \"a\\\$b/"; #"
assert_complete_dir {e"} $cmd "$::srcdir/fixtures/_filedir"; #" assert_complete_dir "\b\b\b\b\b$::srcdirabs/fixtures/_filedir/a\\\\\$b/h\\\"" $cmd "$::srcdir/fixtures/_filedir"
sync_after_int sync_after_int
set cmd "$name \"a b/"; #" set cmd "$name \"a\\b/"; #"
assert_complete_dir {i"} $cmd "$::srcdir/fixtures/_filedir"; #" assert_complete_dir "\b\b\bb/e\\\"" $cmd "$::srcdir/fixtures/_filedir"
sync_after_int sync_after_int
set cmd "$name \"a'b/"; #" set cmd "$name \"a\\\\b/"; #"
assert_complete_dir {c"} $cmd "$::srcdir/fixtures/_filedir"; #" assert_complete_dir {g"} $cmd "$TESTDIR/tmp"; #"
sync_after_int sync_after_int
set cmd "$name \"a\\\"b/"; #" set cmd "$name \"a&b/"; #"
assert_complete_dir {d"} $cmd "$::srcdir/fixtures/_filedir"; #" assert_complete_dir {f"} $cmd "$::srcdir/fixtures/_filedir"; #"
sync_after_int sync_after_int
set cmd "$name \"a\\\$b/"; #"
assert_complete_dir "\b\b\b\b\b$::srcdirabs/fixtures/_filedir/a\\\\\$b/h\\\"" $cmd "$::srcdir/fixtures/_filedir"
sync_after_int
set cmd "$name \"a\\b/"; #"
assert_complete_dir "\b\b\bb/e\\\"" $cmd "$::srcdir/fixtures/_filedir"
sync_after_int
set cmd "$name \"a\\\\b/"; #"
assert_complete_dir {g"} $cmd "$TESTDIR/tmp"; #"
sync_after_int
set cmd "$name \"a&b/"; #"
assert_complete_dir {f"} $cmd "$::srcdir/fixtures/_filedir"; #"
sync_after_int
}; # if 4.0.0 < bash-version > 4.0.34
}; # foreach }; # foreach
@ -249,13 +237,12 @@ sync_after_int
set test "completing f aé should return g" set test "completing f aé should return g"
# Execute this test only on bash >= 4 with LC_CTYPE matching *UTF-8* # Execute this test only with LC_CTYPE matching *UTF-8*
# See also: http://www.mail-archive.com/bash-completion-devel\ # See also: http://www.mail-archive.com/bash-completion-devel\
# @lists.alioth.debian.org/msg02265.html # @lists.alioth.debian.org/msg02265.html
# Don't execute this test on expect-5.44 cause it will segfault # Don't execute this test on expect-5.44 cause it will segfault
# See also: Alioth #312792 # See also: Alioth #312792
if { if {
[lindex $::BASH_VERSINFO 0] >= 4 &&
[string first "UTF-8" $::LC_CTYPE] != -1 && [string first "UTF-8" $::LC_CTYPE] != -1 &&
[string first 5.44 [exp_version]] != 0 [string first 5.44 [exp_version]] != 0
} { } {

View File

@ -97,27 +97,13 @@ sync_after_int
set test {a 'b c|}; # | = cursor position set test {a 'b c|}; # | = cursor position
if { set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1}
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {
set cmd {COMP_WORDS=(a "'" b c); COMP_CWORD=3}
} else {
set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1}
}
append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_comp_words_by_ref cur prev; echo "$cur $prev"} append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_comp_words_by_ref cur prev; echo "$cur $prev"}
send "$cmd\r" send "$cmd\r"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
expect { expect {
-ex "'b c a\r\n/@" { pass "$test" } -ex "'b c a\r\n/@" { pass "$test" }
-ex "c b\r\n/@" { -ex "c b\r\n/@" { fail "$test" }
if {
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {xfail "$test"} {fail "$test"}
}
} }
@ -125,15 +111,7 @@ sync_after_int
set test {a "b c|}; #"# | = cursor position set test {a "b c|}; #"# | = cursor position
if { set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1}
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {
set cmd {COMP_WORDS=(a "\"" b c); COMP_CWORD=3}
} else {
set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1}
}
append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6} append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6}
assert_bash_exec $cmd assert_bash_exec $cmd
set cmd {_get_comp_words_by_ref cur prev; echo "$cur $prev"}; set cmd {_get_comp_words_by_ref cur prev; echo "$cur $prev"};
@ -141,13 +119,7 @@ send "$cmd\r"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
expect { expect {
-ex "\"b c a\r\n/@" { pass "$test" } -ex "\"b c a\r\n/@" { pass "$test" }
-ex "c b\r\n/@" { -ex "c b\r\n/@" { fail "$test" }
if {
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {xfail "$test"} {fail "$test"}
}
} }
@ -155,13 +127,8 @@ sync_after_int
set test {a b:c| with WORDBREAKS += :}; # | = cursor position set test {a b:c| with WORDBREAKS += :}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1} set expected {"c :"}
set expected {"b:c a"}
} else {
set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3}
set expected {"c :"}
}
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5} append cmd {; COMP_LINE='a b:c'; COMP_POINT=5}
# NOTE: Split-send cmd to prevent backspaces (\008) in output # NOTE: Split-send cmd to prevent backspaces (\008) in output
assert_bash_exec $cmd $test assert_bash_exec $cmd $test
@ -173,11 +140,7 @@ sync_after_int
set test {a b:c| with WORDBREAKS -= :}; # | = cursor position set test {a b:c| with WORDBREAKS -= :}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1}
} else {
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
}
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5} append cmd {; COMP_LINE='a b:c'; COMP_POINT=5}
assert_bash_exec $cmd $test assert_bash_exec $cmd $test
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
@ -188,11 +151,7 @@ sync_after_int
set test {a b c:| with WORDBREAKS -= :}; # | = cursor position set test {a b c:| with WORDBREAKS -= :}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3}
set cmd {COMP_WORDS=(a b c:); COMP_CWORD=2}
} else {
set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3}
}
append cmd {; COMP_LINE='a b c:'; COMP_POINT=6} append cmd {; COMP_LINE='a b c:'; COMP_POINT=6}
assert_bash_exec $cmd $test assert_bash_exec $cmd $test
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
@ -203,11 +162,7 @@ sync_after_int
set test {a b:c | with WORDBREAKS -= :}; # | = cursor position set test {a b:c | with WORDBREAKS -= :}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b : c ''); COMP_CWORD=4}
set cmd {COMP_WORDS=(a b:c ''); COMP_CWORD=2}
} else {
set cmd {COMP_WORDS=(a b : c ''); COMP_CWORD=4}
}
append cmd {; COMP_LINE='a b:c '; COMP_POINT=6} append cmd {; COMP_LINE='a b:c '; COMP_POINT=6}
assert_bash_exec $cmd $test assert_bash_exec $cmd $test
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
@ -228,11 +183,7 @@ sync_after_int
set test {a b::| with WORDBREAKS -= : should return b::}; # | = cursor position set test {a b::| with WORDBREAKS -= : should return b::}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2}
set cmd {COMP_WORDS=(a "b::"); COMP_CWORD=1}
} else {
set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2}
}
append cmd {; COMP_LINE='a b::'; COMP_POINT=5} append cmd {; COMP_LINE='a b::'; COMP_POINT=5}
assert_bash_exec $cmd assert_bash_exec $cmd
set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"} set cmd {_get_comp_words_by_ref -n : cur prev; echo "$cur $prev"}
@ -264,14 +215,9 @@ assert_bash_list c $cmd $test
sync_after_int sync_after_int
set test {a b=c| should return b=c (bash-3) or c (bash-4)}; # | = cursor position set test {a b=c| should return c}; # | = cursor position
if {[lindex $::BASH_VERSINFO] <= 3} { set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a "b=c"); COMP_CWORD=1} set expected c
set expected b=c
} else {
set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3}
set expected c
}
append cmd {; COMP_LINE='a b=c'; COMP_POINT=5} append cmd {; COMP_LINE='a b=c'; COMP_POINT=5}
assert_bash_exec $cmd assert_bash_exec $cmd
set cmd {_get_comp_words_by_ref cur prev; echo "$cur"} set cmd {_get_comp_words_by_ref cur prev; echo "$cur"}
@ -325,15 +271,7 @@ sync_after_int
set test {a 'b&c| should return 'b&c}; # | = cursor position set test {a 'b&c| should return 'b&c}; # | = cursor position
if { set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1}
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {
set cmd {COMP_WORDS=(a "'" b "&" c); COMP_CWORD=4}
} else {
set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1}
}
append cmd {; COMP_LINE="a 'b&c"; COMP_POINT=6} append cmd {; COMP_LINE="a 'b&c"; COMP_POINT=6}
assert_bash_exec $cmd assert_bash_exec $cmd
set cmd {_get_comp_words_by_ref cur prev; printf %s "$cur"} set cmd {_get_comp_words_by_ref cur prev; printf %s "$cur"}
@ -341,13 +279,7 @@ send "$cmd\r"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
expect { expect {
-ex "'b&c/@" { pass "$test" } -ex "'b&c/@" { pass "$test" }
-ex "c/@" { -ex "c/@" { fail "$test" }
if {
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {xfail "$test"} {fail "$test"}
}
} }
@ -409,11 +341,7 @@ sync_after_int
set test {a b: c| with WORDBREAKS -= :}; # | = cursor position set test {a b: c| with WORDBREAKS -= :}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a b: c); COMP_CWORD=2}
} else {
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
}
append cmd {; COMP_LINE='a b: c'; COMP_POINT=6} append cmd {; COMP_LINE='a b: c'; COMP_POINT=6}
assert_bash_exec $cmd $test assert_bash_exec $cmd $test
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"} set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
@ -424,11 +352,7 @@ sync_after_int
set test {a b :c| with WORDBREAKS -= :}; # | = cursor position set test {a b :c| with WORDBREAKS -= :}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a b :c); COMP_CWORD=2}
} else {
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
}
append cmd {; COMP_LINE='a b :c'; COMP_POINT=6} append cmd {; COMP_LINE='a b :c'; COMP_POINT=6}
assert_bash_exec $cmd $test assert_bash_exec $cmd $test
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"} set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}
@ -439,11 +363,7 @@ sync_after_int
set test {a b\ :c| with WORDBREAKS -= :}; # | = cursor position set test {a b\ :c| with WORDBREAKS -= :}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a "b\\ " : c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a "b\\ :c"); COMP_CWORD=1}
} else {
set cmd {COMP_WORDS=(a "b\\ " : c); COMP_CWORD=3}
}
append cmd {; COMP_LINE='a b\ :c'; COMP_POINT=7} append cmd {; COMP_LINE='a b\ :c'; COMP_POINT=7}
assert_bash_exec $cmd $test assert_bash_exec $cmd $test
set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"} set cmd {_get_comp_words_by_ref -n : words; echo "${words[@]}"}

View File

@ -97,27 +97,13 @@ sync_after_int
set test {a 'b c| should return 'b c}; # | = cursor position set test {a 'b c| should return 'b c}; # | = cursor position
if { set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1}
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {
set cmd {COMP_WORDS=(a "'" b c); COMP_CWORD=3}
} else {
set cmd {COMP_WORDS=(a "'b c"); COMP_CWORD=1}
}
append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_cword} append cmd {; COMP_LINE="a 'b c"; COMP_POINT=6; _get_cword}
send "$cmd\r" send "$cmd\r"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
expect { expect {
-ex "'b c/@" { pass "$test" } -ex "'b c/@" { pass "$test" }
-ex "c/@" { -ex "c/@" { fail "$test" }
if {
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {xfail "$test"} {fail "$test"}
}
} }
@ -125,41 +111,22 @@ sync_after_int
set test {a "b c| should return "b c}; # | = cursor position set test {a "b c| should return "b c}; # | = cursor position
if { set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1}
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {
set cmd {COMP_WORDS=(a "\"" b c); COMP_CWORD=3}
} else {
set cmd {COMP_WORDS=(a "\"b c"); COMP_CWORD=1}
}
append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6; _get_cword}; append cmd {; COMP_LINE="a \"b c"; COMP_POINT=6; _get_cword};
send "$cmd\r" send "$cmd\r"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
expect { expect {
-ex "\"b c/@" { pass "$test" } -ex "\"b c/@" { pass "$test" }
-ex "c/@" { -ex "c/@" { fail "$test" }
if {
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {xfail "$test"} {fail "$test"}
}
} }
sync_after_int sync_after_int
set test {a b:c| with WORDBREAKS += : should return b:c (bash-3) or c (bash-4)}; # | = cursor position set test {a b:c| with WORDBREAKS += : should return c}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1} set expected c
set expected b:c
} else {
set cmd {add_comp_wordbreak_char :; COMP_WORDS=(a b : c); COMP_CWORD=3}
set expected c
}
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword; echo} append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword; echo}
assert_bash_list $expected $cmd $test assert_bash_list $expected $cmd $test
@ -168,11 +135,7 @@ sync_after_int
set test {a b:c| with WORDBREAKS -= : should return b:c}; # | = cursor position set test {a b:c| with WORDBREAKS -= : should return b:c}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a "b:c"); COMP_CWORD=1}
} else {
set cmd {COMP_WORDS=(a b : c); COMP_CWORD=3}
}
append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword :; echo} append cmd {; COMP_LINE='a b:c'; COMP_POINT=5; _get_cword :; echo}
assert_bash_list b:c $cmd $test assert_bash_list b:c $cmd $test
@ -181,11 +144,7 @@ sync_after_int
set test {a b c:| with WORDBREAKS -= : should return c:}; # | = cursor position set test {a b c:| with WORDBREAKS -= : should return c:}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3}
set cmd {COMP_WORDS=(a b c:); COMP_CWORD=2}
} else {
set cmd {COMP_WORDS=(a b c :); COMP_CWORD=3}
}
append cmd {; COMP_LINE='a b c:'; COMP_POINT=6; _get_cword :; echo} append cmd {; COMP_LINE='a b c:'; COMP_POINT=6; _get_cword :; echo}
assert_bash_list c: $cmd $test assert_bash_list c: $cmd $test
@ -202,11 +161,7 @@ sync_after_int
set test {a b::| with WORDBREAKS -= : should return b::}; # | = cursor position set test {a b::| with WORDBREAKS -= : should return b::}; # | = cursor position
if {[lindex $::BASH_VERSINFO 0] <= 3} { set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2}
set cmd {COMP_WORDS=(a "b::"); COMP_CWORD=1}
} else {
set cmd {COMP_WORDS=(a b ::); COMP_CWORD=2}
}
append cmd {; COMP_LINE='a b::'; COMP_POINT=5; _get_cword :; echo} append cmd {; COMP_LINE='a b::'; COMP_POINT=5; _get_cword :; echo}
assert_bash_list b:: $cmd $test assert_bash_list b:: $cmd $test
@ -232,14 +187,9 @@ assert_bash_list c $cmd $test
sync_after_int sync_after_int
set test {a b=c| should return b=c (bash-3) or c (bash-4)}; # | = cursor position set test {a b=c| should return c}; # | = cursor position
if {[lindex $::BASH_VERSINFO] <= 3} { set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3}
set cmd {COMP_WORDS=(a "b=c"); COMP_CWORD=1} set expected c
set expected b=c
} else {
set cmd {COMP_WORDS=(a b = c); COMP_CWORD=3}
set expected c
}
append cmd {; COMP_LINE='a b=c'; COMP_POINT=5; _get_cword; echo} append cmd {; COMP_LINE='a b=c'; COMP_POINT=5; _get_cword; echo}
assert_bash_list $expected $cmd $test assert_bash_list $expected $cmd $test
@ -286,27 +236,13 @@ sync_after_int
set test {a 'b&c| should return 'b&c}; # | = cursor position set test {a 'b&c| should return 'b&c}; # | = cursor position
if { set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1}
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {
set cmd {COMP_WORDS=(a "'" b "&" c); COMP_CWORD=4}
} else {
set cmd {COMP_WORDS=(a "'b&c"); COMP_CWORD=1}
}
append cmd {; COMP_LINE="a 'b&c"; COMP_POINT=6; _get_cword} append cmd {; COMP_LINE="a 'b&c"; COMP_POINT=6; _get_cword}
send "$cmd\r" send "$cmd\r"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
expect { expect {
-ex "'b&c/@" { pass "$test" } -ex "'b&c/@" { pass "$test" }
-ex "c/@" { -ex "c/@" { fail "$test" }
if {
[lindex $::BASH_VERSINFO 0] == 4 &&
[lindex $::BASH_VERSINFO 1] == 0 &&
[lindex $::BASH_VERSINFO 2] < 35
} {xfail "$test"} {fail "$test"}
}
} }

View File

@ -11,31 +11,15 @@ proc teardown {} {
setup setup
if {[lindex $::BASH_VERSINFO 0] <= 3} { set test {compgen -f a\\\'b/ should return a\'b/c}
set test {compgen -f a\\\\\\\'b/ on bash-3 should return a\'b/c}; set cmd {compgen -f a\\\'b/}
set cmd {compgen -f a\\\\\\\'b/}
} else {
set test {compgen -f a\\\'b/ on bash-4 should return a\'b/c};
set cmd {compgen -f a\\\'b/}
}
set dir $::srcdir/fixtures/compgen set dir $::srcdir/fixtures/compgen
assert_bash_exec "cd $dir" assert_bash_exec "cd $dir"
send "$cmd\r" send "$cmd\r"
expect -ex "$cmd\r\n" expect -ex "$cmd\r\n"
expect { expect {
-re {a\\\'b/c} { -re {a\\\'b/c} { pass $test }
# On bash-3.2, compgen returns inconsequent output -re {a'b/c} { fail $test }
if {
[lindex $::BASH_VERSINFO 0] >= 4 || (
[lindex $::BASH_VERSINFO 0] == 3 &&
[lindex $::BASH_VERSINFO 1] == 2
)
} {pass $test} else {fail $test}
}
-re {a'b/c} {
if {[lindex $::BASH_VERSINFO 0] <= 3 } \
{pass $test} else {fail $test}
}
-re /@ { pass "$test" } -re /@ { pass "$test" }
-re eof { unresolved "eof" } -re eof { unresolved "eof" }
} }