sievemgr.bash 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # sievemgr.bash - Bash completion script for SieveManager
  2. #
  3. # Copyright 2024 Odin Kroeger
  4. #
  5. # This file is part of SieveManager.
  6. #
  7. # SieveManager is free software: you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License as
  9. # published by the Free Software Foundation, either version 3 of
  10. # the License, or (at your option) any later version.
  11. #
  12. # SieveManager is distributed in the hope that it will be useful,
  13. # but WITHOUT ALL WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with SieveManager. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. _comp_sievemgr() {
  21. local cmd="$1" word="$2" pre="$3"
  22. set -- $COMP_LINE
  23. shift
  24. local argdel=0
  25. while [ $# -gt 0 ]
  26. do
  27. case $1 in
  28. (--) shift
  29. break
  30. ;;
  31. (-*[co]) local optopt="${1: -1}"
  32. local optarg="${1#-*$optopt}"
  33. if [ "$optarg" ]
  34. then
  35. shift
  36. elif
  37. [ $# -gt 1 ]
  38. then
  39. shift 2
  40. else
  41. shift
  42. argdel=1
  43. fi
  44. ;;
  45. (-*) local optopt="${1#-}"
  46. shift ;;
  47. (*) break
  48. esac
  49. done
  50. case $COMP_LINE in
  51. (*" ") local argidx=$(($# - argdel + 1)) ;;
  52. (*) local argidx=$(($# - argdel)) ;;
  53. esac
  54. local replies
  55. case $argidx in
  56. (0) case $word in
  57. (--) COMPREPLY=()
  58. return
  59. ;;
  60. (-) COMPREPLY=(-N -C -V -c -d -e -f
  61. -h -i -o -q -s -v)
  62. return
  63. ;;
  64. (-*[co]) :
  65. ;;
  66. (-*) COMPREPLY=("$word")
  67. return
  68. ;;
  69. esac
  70. case $optopt in
  71. (o) replies=(
  72. 'alias='
  73. 'backups='
  74. 'cafile='
  75. 'cadir='
  76. 'cert='
  77. 'confdir='
  78. 'confirm='
  79. 'getkeypass='
  80. 'getpass='
  81. 'host='
  82. 'key='
  83. 'login='
  84. 'ocsp=no'
  85. 'ocsp=yes'
  86. 'port='
  87. 'tls=no'
  88. 'tls=yes'
  89. 'saslmechs='
  90. 'saslprep=usernames'
  91. 'saslprep=passwords'
  92. 'saslprep=all'
  93. 'saslprep=none'
  94. 'verbosity=auth'
  95. 'verbosity=debug'
  96. 'verbosity=error'
  97. 'verbosity=info'
  98. 'verbosity=warning'
  99. 'x509strict=no'
  100. 'x509strict=yes'
  101. )
  102. ;;
  103. (*) COMPREPLY=("$word")
  104. return
  105. esac
  106. ;;
  107. (1) local home="${HOME-}"
  108. [ "$home" ] && eval home=~
  109. local xdg_data_home="${XDG_DATA_HOME:-"$home/.config"}"
  110. local config key value
  111. for config in \
  112. "/etc/sieve/config" \
  113. "/etc/sieve.cf" \
  114. "$xdg_data_home/sieve/config" \
  115. "$home/.sieve/config" \
  116. "$home/.sieve.cf"
  117. do
  118. [ -e "$config" ] || continue
  119. while read -r key value
  120. do
  121. case $key in
  122. (account|alias) : ;;
  123. (*) continue
  124. esac
  125. case $word in
  126. (*@*) local netloc="${word##*@}"
  127. case $value in ("$netloc"*)
  128. COMPREPLY+=("${word%@*}@$value")
  129. esac
  130. ;;
  131. (*) case $value in ("$word"*)
  132. COMPREPLY+=("$value")
  133. esac
  134. ;;
  135. esac
  136. done <"$config"
  137. done
  138. return
  139. ;;
  140. (2) local replies=(
  141. 'about'
  142. 'activate'
  143. 'caps'
  144. 'cat'
  145. 'cd'
  146. 'cert'
  147. 'check'
  148. 'cmp'
  149. 'cp'
  150. 'deactivate'
  151. 'diff'
  152. 'ed'
  153. 'exit'
  154. 'get'
  155. 'help'
  156. 'ls'
  157. 'more'
  158. 'mv'
  159. 'put'
  160. 'python'
  161. 'rm'
  162. 'sh'
  163. 'su'
  164. 'vi'
  165. 'xargs'
  166. )
  167. ;;
  168. esac
  169. local reply
  170. for reply in "${replies[@]}"
  171. do
  172. case $reply in
  173. ("$word"*) COMPREPLY+=("$reply")
  174. esac
  175. done
  176. if [ "$optopt" = o ] &&
  177. [ "${#COMPREPLY[@]}" -eq 1 ] &&
  178. [ "${COMPREPLY[0]: -1}" = '=' ]
  179. then
  180. compopt -o nospace
  181. fi
  182. } && complete -F _comp_sievemgr -o default sievemgr