123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- # sievemgr.bash - Bash completion script for SieveManager
- #
- # Copyright 2024 Odin Kroeger
- #
- # This file is part of SieveManager.
- #
- # SieveManager is free software: you can redistribute it and/or
- # modify it under the terms of the GNU General Public License as
- # published by the Free Software Foundation, either version 3 of
- # the License, or (at your option) any later version.
- #
- # SieveManager is distributed in the hope that it will be useful,
- # but WITHOUT ALL WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with SieveManager. If not, see <https://www.gnu.org/licenses/>.
- #
- _comp_sievemgr() {
- local cmd="$1" word="$2" pre="$3"
- set -- $COMP_LINE
- shift
- local argdel=0
- while [ $# -gt 0 ]
- do
- case $1 in
- (--) shift
- break
- ;;
- (-*[co]) local optopt="${1: -1}"
- local optarg="${1#-*$optopt}"
- if [ "$optarg" ]
- then
- shift
- elif
- [ $# -gt 1 ]
- then
- shift 2
- else
- shift
- argdel=1
- fi
- ;;
- (-*) local optopt="${1#-}"
- shift ;;
- (*) break
- esac
- done
- case $COMP_LINE in
- (*" ") local argidx=$(($# - argdel + 1)) ;;
- (*) local argidx=$(($# - argdel)) ;;
- esac
- local replies
- case $argidx in
- (0) case $word in
- (--) COMPREPLY=()
- return
- ;;
- (-) COMPREPLY=(-N -C -V -c -d -e -f
- -h -i -o -q -s -v)
- return
- ;;
- (-*[co]) :
- ;;
- (-*) COMPREPLY=("$word")
- return
- ;;
- esac
- case $optopt in
- (o) replies=(
- 'alias='
- 'backups='
- 'cafile='
- 'cadir='
- 'cert='
- 'confdir='
- 'confirm='
- 'getkeypass='
- 'getpass='
- 'host='
- 'key='
- 'login='
- 'ocsp=no'
- 'ocsp=yes'
- 'port='
- 'tls=no'
- 'tls=yes'
- 'saslmechs='
- 'saslprep=usernames'
- 'saslprep=passwords'
- 'saslprep=all'
- 'saslprep=none'
- 'verbosity=auth'
- 'verbosity=debug'
- 'verbosity=error'
- 'verbosity=info'
- 'verbosity=warning'
- 'x509strict=no'
- 'x509strict=yes'
- )
- ;;
- (*) COMPREPLY=("$word")
- return
- esac
- ;;
- (1) local home="${HOME-}"
- [ "$home" ] && eval home=~
- local xdg_data_home="${XDG_DATA_HOME:-"$home/.config"}"
- local config key value
- for config in \
- "/etc/sieve/config" \
- "/etc/sieve.cf" \
- "$xdg_data_home/sieve/config" \
- "$home/.sieve/config" \
- "$home/.sieve.cf"
- do
- [ -e "$config" ] || continue
- while read -r key value
- do
- case $key in
- (account|alias) : ;;
- (*) continue
- esac
- case $word in
- (*@*) local netloc="${word##*@}"
- case $value in ("$netloc"*)
- COMPREPLY+=("${word%@*}@$value")
- esac
- ;;
- (*) case $value in ("$word"*)
- COMPREPLY+=("$value")
- esac
- ;;
- esac
- done <"$config"
- done
- return
- ;;
- (2) local replies=(
- 'about'
- 'activate'
- 'caps'
- 'cat'
- 'cd'
- 'cert'
- 'check'
- 'cmp'
- 'cp'
- 'deactivate'
- 'diff'
- 'ed'
- 'exit'
- 'get'
- 'help'
- 'ls'
- 'more'
- 'mv'
- 'put'
- 'python'
- 'rm'
- 'sh'
- 'su'
- 'vi'
- 'xargs'
- )
- ;;
- esac
- local reply
- for reply in "${replies[@]}"
- do
- case $reply in
- ("$word"*) COMPREPLY+=("$reply")
- esac
- done
- if [ "$optopt" = o ] &&
- [ "${#COMPREPLY[@]}" -eq 1 ] &&
- [ "${COMPREPLY[0]: -1}" = '=' ]
- then
- compopt -o nospace
- fi
- } && complete -F _comp_sievemgr -o default sievemgr
|