Репозиторий Sisyphus
Последнее обновление: 30 сентября 2022 | Пакетов: 17695 | Посещений: 25051571
en ru br
Репозитории ALT
S:2.11-alt2.git.157.g59d2322e
5.1: 20060301-alt06
4.1: 20060301-alt05
4.0: 20060301-alt03
3.0: 20050712-alt01
www.altlinux.org/Changes

Группа :: Интерпретаторы команд
Пакет: bash-completion

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

# mutt completion
#
# Mutt doesn't have an "addressbook" like Pine, but it has aliases and
# a "query" function to retrieve addresses, so that's what we use here.

have mutt || have muttng && {
_muttaddr()
{
_muttaliases
_muttquery

cur=`_get_cword`
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -u -- "$cur" ) )

return 0
}

_muttconffiles()
{
local file sofar
local -a newconffiles

sofar=" $1 "
shift
while [[ "$1" ]]; do
newconffiles=( $(sed -rn 's|^source[[:space:]]+([^[:space:]]+).*$|\1|p' $(eval echo $1) ) )
for file in "${newconffiles[@]}"; do
[[ ! "$file" ]] || [[ "${sofar/ ${file} / }" != "$sofar" ]] &&
continue
sofar="$sofar $file"
sofar=" $(eval _muttconffiles \"$sofar\" $file) "
done
shift
done
echo $sofar
}

_muttaliases()
{
local cur muttrc muttcmd=${COMP_WORDS[0]}
local -a conffiles aliases
cur=`_get_cword =`

[ -f ~/.${muttcmd}/${muttcmd}rc ] && muttrc="~/.${muttcmd}/${muttcmd}rc"
[ -f ~/.${muttcmd}rc ] && muttrc="~/.${muttcmd}rc"
[ -z "$muttrc" ] && return 0

conffiles=( $(eval _muttconffiles $muttrc $muttrc) )
aliases=( $( sed -rn 's|^alias[[:space:]]+([^[:space:]]+).*$|\1|p' \
$(eval echo "${conffiles[@]}") ) )
COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${aliases[*]}" -- "$cur" ) )

return 0
}

_muttquery()
{
local cur querycmd muttcmd=${COMP_WORDS[0]}
local -a queryresults
cur=`_get_cword`

querycmd="$( $muttcmd -Q query_command | sed -r 's|^query_command=\"(.*)\"$|\1|; s|%s|'$cur'|' )"
if [ -z "$cur" -o -z "$querycmd" ]; then
queryresults=()
else
queryresults=( $( $querycmd | sed -nr '2,$s|^([^[:space:]]+).*|\1|p' ) )
fi

COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "${queryresults[*]}" \
-- "$cur" ) )

return 0
}

_muttfiledir()
{
local cur prev folder spoolfile muttcmd=${COMP_WORDS[0]}
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ ${BASH_VERSINFO[0]} == 4 && $prev == = ]]; then
cur=${COMP_WORDS[COMP_CWORD-1]}${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-2]}
fi

# This is currently not working so well. Perhaps this function should
# just call _filedir() for the moment.
if [[ $cur == [=+]* ]]; then
folder="$( $muttcmd -Q folder | sed -r 's|^folder=\"(.*)\"$|\1|' )"
: folder:=~/Mail

# Match any file in $folder beginning with $cur
# (minus the leading '=' sign).
COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) )
COMPREPLY=( ${COMPREPLY[@]#$folder/} )
return 0
elif [ "$cur" == !* ]; then
spoolfile="$( $muttcmd -Q spoolfile | \
sed -r 's|^spoolfile=\"(.*)\"$|\1|' )"
[ ! -z "$spoolfile" ] && eval cur="${cur/^!/$spoolfile}";
fi
_filedir

return 0
}

_mutt()
{
local cur prev
cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ ${BASH_VERSINFO[0]} == 4 && $prev == = ]]; then
cur=${COMP_WORDS[COMP_CWORD-1]}${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-2]}
fi

COMPREPLY=()

case "$cur" in
-*)
COMPREPLY=( $( compgen -W '-A -a -b -c -e -f -F -H -i -m -n \
-p -Q -R -s -v -x -y -z -Z -h' -- "$cur" ) )
return 0
;;
*)
case "$prev" in
-@(a|f|F|H|i))
_muttfiledir
return 0
;;
-A)
_muttaliases
return 0
;;
-@(e|m|Q|s|h|p|R|v|y|z|Z))
return 0
;;
*)
_muttaddr
return 0
;;
esac
;;
esac

}
complete -F _mutt $default $filenames mutt muttng
}

# 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
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin