bash-completion/test/lib/library.sh
Freddy Vulto 08c5878483 Merged __get_cword3 & __get_cword4 to _get_cword
Actually enhanced __get_cword3 to _get_cword, and removed __get_cword4.
__get_cword4 could handle chars to exclude from COMP_WORDBREAKS, but
failed with partial quoted arguments (e.g. "a 'b c|", | = cursor
position).  This was no problem till bash-4.0.35, because bash < 4.0.35
also returned partial quoted arguments incorrectly.  See also:
http://www.mail-archive.com/bug-bash@gnu.org/msg06094.html

Now that bash-4.0.35 returns quoted arguments ok, __get_cword3 is
enhanced to also handle chars to exclude from COMP_WORDBREAKS.  Because
__get_cword3 also handles partial quoted arguments correctly, this makes
__get_cword3 suitable for bash-4 as well.
2009-12-06 23:16:31 +01:00

72 lines
1.8 KiB
Bash

# Bash library for bash-completion DejaGnu testsuite
# @param $1 Char to add to $COMP_WORDBREAKS
# @see remove_comp_wordbreak_char()
add_comp_wordbreak_char() {
if [ ${BASH_VERSINFO[0]} -ge 4 ]; then
[[ "${COMP_WORDBREAKS//[^$1]}" ]] || COMP_WORDBREAKS=$COMP_WORDBREAKS$1
fi
} # add_comp_wordbreak_char()
# Diff environment files to detect if environment is unmodified
# @param $1 File 1
# @param $2 File 2
# @param $3 Additional sed script
diff_env() {
diff "$1" "$2" | sed -e "
/^[0-9,]\{1,\}[acd]/d # Remove diff line indicators
/---/d # Remove diff block separators
/[<>] _=/d # Remove underscore variable
/[<>] PPID=/d # Remove PPID bash variable
$3"
} # diff_env()
# Output array elements, sorted and separated by newline
# Unset variable after outputting.
# @param $1 Name of array variable to process
echo_array() {
local name=$1[@]
printf "%s\n" "${!name}" | sort
} # echo_array()
# Check if current bash version meets specified minimum
# @param $1 (integer) Major version number
# @param $2 (integer) Minor version number
# @param $3 (integer) Patch level
# @return 0 if success, > 0 if not
is_bash_version_minimal() {
[[ (
${BASH_VERSINFO[0]} -gt $1
) || (
${BASH_VERSINFO[0]} -eq $1 &&
${BASH_VERSINFO[1]} -gt $2
) || (
${BASH_VERSINFO[0]} -eq $1 &&
${BASH_VERSINFO[1]} -eq $2 &&
${BASH_VERSINFO[2]} -ge $3
)
]]
} # is_bash_version_minimal()
# @param $1 Char to remove from $COMP_WORDBREAKS
# @see add_comp_wordbreak_char()
remove_comp_wordbreak_char() {
if [ ${BASH_VERSINFO[0]} -ge 4 ]; then
COMP_WORDBREAKS=${COMP_WORDBREAKS//$1}
fi
} # remove_comp_wordbreak_char()
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh