Usage: _get_comp_words_by_ref [OPTIONS] [VARNAMES]
Available VARNAMES:
cur Return cur within varname "cur"
prev Return prev within varname "prev"
words Return words within varname "words"
cword Return cword within varname "cword"
Available OPTIONS:
-n EXCLUDE Characters out of $COMP_WORDBREAKS which should NOT be
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 colon (:) as -n option in this case. Bash-3
doesn't do word splitting, so this ensures we get the same
word on both bash-3 and bash-4.
-c VARNAME Return cur within specified VARNAME
-p VARNAME Return prev within specified VARNAME
-w VARNAME Return words within specified VARNAME
-i VARNAME Return words within specified VARNAME
Example usage:
$ _get_comp_words_by_ref -n : cur prev
regardless of $cur beginning with ' or not"), because this is failing
tests:
FAIL: completing f a\'b/ should return i
FAIL: completing f a\"b/ should return i
FAIL: f a\$b/ should show completions
FAIL: f a\\b/ should show completions
FAIL: completing f2 a\'b/ should return i
FAIL: completing f2 a\"b/ should return i
FAIL: f2 a\$b/ should show completions
FAIL: f2 a\\b/ should show completions
- Fix _filedir to check for availability of COMP_WORDS (_filedir runs from
within a completion instead of the command line) when doing a `complete -p
${COMP_WORDS[0]'
- Fix _filedir usage comment
- Enhanced _filedir tests
- Added _filedir test "completing with filter '.e1' should show completions"
This solves the following problems:
- now one function call suffices instead of two (_get_cword; _get_pword) if
subsequent words need to be retrieved. Also more than two words can be
retrieved at once, e.g.: _get_comp_words_by_ref cur prev prev2 prev3
Also this prevents passing of `wordbreakchars' to differ in calls to
`_get_cword' and `_get_pword', e.g.: _get_comp_words_by_ref -n : cur prev
- passing by reference, no subshell call necessary anymore
- _get_pword now also takes into account the cursor position
Added testsuite proc `assert_no_output()'
Word of caution:
The passing-arguments-by-ref system in bash doesn't work if the new variable is
also declared local. For example:
t() {
local a
# ...
eval $1=b
}
a=c; t a; echo $a # Outputs "c", should be "b"
# Variable "a" is 'forbidden'
To make name collissions like this less likely to happen, but make the real
function still use readable variables, I've wrapped the `*_by_ref'
functions within an additional layer using variables prefixed with double
underscores (__). For example:
_t() {
# Readable variables can still be used here
local a
# ...
eval $1=b
}
t() {
local __a
_t __a
eval $1=\$__a
}
a=c; t a; echo $a # Outputs "b"
# Variable "__a" is 'forbidden'
Now only more obfuscated variables (starting with double prefix (__)) are
forbidden to use.
- assert_source_completions()
- is_bash_completion_installed_for()
This allows for cleaner invocation of tests in `lib/completions/'. For
example, `completion/perldoc.exp' now just contains:
assert_source_completions perldoc
Skeleton test files for a command can be generated with:
$ ./generate <command>
Make `assert_bash_type' reflect bash-side where `have perl' is checked,
and not perldoc, to determine whether `perldoc' completion should be
installed.