Cleanups: use usual globs instead of substring matches or substitutions.

This commit is contained in:
Ville Skyttä 2011-11-09 22:24:39 +02:00
parent d54db3507d
commit 1d48f79b9c
4 changed files with 13 additions and 17 deletions

View File

@ -256,14 +256,11 @@ __reassemble_comp_words_by_ref()
# empty and is word made up of just word separator characters to # empty and is word made up of just word separator characters to
# be excluded and is current word not preceded by whitespace in # be excluded and is current word not preceded by whitespace in
# original line? # original line?
while [[ $i -gt 0 && ${COMP_WORDS[$i]} && while [[ $i -gt 0 && ${COMP_WORDS[$i]} == +([$exclude]) ]]; do
${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]}
]]; do
# Is word separator not preceded by whitespace in original line # Is word separator not preceded by whitespace in original line
# and are we not going to append to word 0 (the command # and are we not going to append to word 0 (the command
# itself), then append to current word. # itself), then append to current word.
[[ ${line:0:1} != ' ' && ${line:0:1} != $'\t' ]] && [[ $line != [$' \t']* ]] && (( j >= 2 )) && ((j--))
(( j >= 2 )) && ((j--))
# Append word separator to current or new word # Append word separator to current or new word
ref="$2[$j]" ref="$2[$j]"
eval $2[$j]=\${!ref}\${COMP_WORDS[i]} eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
@ -273,7 +270,7 @@ __reassemble_comp_words_by_ref()
line=${line#*"${COMP_WORDS[$i]}"} line=${line#*"${COMP_WORDS[$i]}"}
# Start new word if word separator in original line is # Start new word if word separator in original line is
# followed by whitespace. # followed by whitespace.
[[ ${line:0:1} == ' ' || ${line:0:1} == $'\t' ]] && ((j++)) [[ $line == [$' \t']* ]] && ((j++))
# Indicate next word if available, else end *both* while and # Indicate next word if available, else end *both* while and
# for loop # for loop
(( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2 (( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2
@ -537,7 +534,7 @@ __ltrim_colon_completions()
# @param $2 Name of variable to return result to # @param $2 Name of variable to return result to
_quote_readline_by_ref() _quote_readline_by_ref()
{ {
if [[ ${1:0:1} == "'" ]]; then if [[ $1 == \'* ]]; then
# Leave out first character # Leave out first character
printf -v $2 %s "${1:1}" printf -v $2 %s "${1:1}"
else else
@ -547,7 +544,7 @@ _quote_readline_by_ref()
# If result becomes quoted like this: $'string', re-evaluate in order to # If result becomes quoted like this: $'string', re-evaluate in order to
# drop the additional quoting. See also: http://www.mail-archive.com/ # drop the additional quoting. See also: http://www.mail-archive.com/
# bash-completion-devel@lists.alioth.debian.org/msg01942.html # bash-completion-devel@lists.alioth.debian.org/msg01942.html
[[ ${!2:0:1} == '$' ]] && eval $2=${!2} [[ ${!2} == \$* ]] && eval $2=${!2}
} # _quote_readline_by_ref() } # _quote_readline_by_ref()
@ -939,9 +936,9 @@ _tilde()
__expand_tilde_by_ref() __expand_tilde_by_ref()
{ {
# Does $1 start with tilde (~)? # Does $1 start with tilde (~)?
if [ "${!1:0:1}" = "~" ]; then if [[ ${!1} == ~* ]]; then
# Does $1 contain slash (/)? # Does $1 contain slash (/)?
if [ "${!1}" != "${!1//\/}" ]; then if [[ ${!1} == */* ]]; then
# Yes, $1 contains slash; # Yes, $1 contains slash;
# 1: Remove * including and after first slash (/), i.e. "~a/b" # 1: Remove * including and after first slash (/), i.e. "~a/b"
# becomes "~a". Double quotes allow eval. # becomes "~a". Double quotes allow eval.

View File

@ -43,7 +43,7 @@ _info()
local i infopath=/usr/share/info local i infopath=/usr/share/info
if [ "${INFOPATH: -1:1}" == ':' ]; then if [[ $INFOPATH == *: ]]; then
infopath=${INFOPATH}${infopath} infopath=${INFOPATH}${infopath}
elif [ ${INFOPATH:+set} ]; then elif [ ${INFOPATH:+set} ]; then
infopath=$INFOPATH infopath=$INFOPATH

View File

@ -22,7 +22,7 @@ _muttrc()
# Search COMP_WORDS for '-F muttrc' or '-Fmuttrc' argument # Search COMP_WORDS for '-F muttrc' or '-Fmuttrc' argument
set -- "${words[@]}" set -- "${words[@]}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then if [[ $1 == -F* ]]; then
if [ ${#1} -gt 2 ]; then if [ ${#1} -gt 2 ]; then
muttrc="$(dequote "${1:2}")" muttrc="$(dequote "${1:2}")"
else else
@ -60,8 +60,7 @@ _muttconffiles()
newconffiles=( $(sed -n 's|^source[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*$|\1|p' $(eval echo $1) ) ) newconffiles=( $(sed -n 's|^source[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*$|\1|p' $(eval echo $1) ) )
for file in "${newconffiles[@]}"; do for file in "${newconffiles[@]}"; do
__expand_tilde_by_ref file __expand_tilde_by_ref file
[[ ! -f "$file" || "${sofar/ ${file} / }" != "$sofar" ]] && [[ ! -f "$file" || $sofar == *\ $file\ * ]] && continue
continue
sofar+=" $file" sofar+=" $file"
sofar=" $(eval _muttconffiles \"$sofar\" $file) " sofar=" $(eval _muttconffiles \"$sofar\" $file) "
done done

View File

@ -158,7 +158,7 @@ _ssh()
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
set -- "${words[@]}" set -- "${words[@]}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then if [[ $1 == -F* ]]; then
if [ ${#1} -gt 2 ]; then if [ ${#1} -gt 2 ]; then
configfile="$(dequote "${1:2}")" configfile="$(dequote "${1:2}")"
else else
@ -221,7 +221,7 @@ _sftp()
# Search COMP_WORDS for '-F configfile' argument # Search COMP_WORDS for '-F configfile' argument
set -- "${words[@]}" set -- "${words[@]}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then if [[ $1 == -F* ]]; then
if [ ${#1} -gt 2 ]; then if [ ${#1} -gt 2 ]; then
configfile="$(dequote "${1:2}")" configfile="$(dequote "${1:2}")"
else else
@ -351,7 +351,7 @@ _scp()
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
set -- "${words[@]}" set -- "${words[@]}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then if [[ $1 == -F* ]]; then
if [ ${#1} -gt 2 ]; then if [ ${#1} -gt 2 ]; then
configfile="$(dequote "${1:2}")" configfile="$(dequote "${1:2}")"
else else