mail 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. _mail_complete_available_addresses ()
  2. {
  3. local prefix="$1"
  4. if [ -z "$_mail_available_addresses" ]
  5. then
  6. # Cache the complete list because it rarely changes and makes
  7. # completion much faster.
  8. _mail_available_addresses="$(${COMP_WORDS[0]} neomutt -A 2> /dev/null \
  9. | cut -f1)"
  10. fi
  11. COMPREPLY=($(compgen -W "$_mail_available_addresses" -- "$prefix"))
  12. }
  13. _mail_is_command ()
  14. {
  15. local word
  16. local result="false"
  17. for word in ${COMP_WORDS[*]}
  18. do
  19. if [ "$word" = "$1" ]
  20. then
  21. result=true
  22. break
  23. fi
  24. done
  25. $result
  26. }
  27. _mail_complete()
  28. {
  29. local word_count=${#COMP_WORDS[*]}
  30. local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
  31. case $COMP_CWORD in
  32. 1)
  33. if [ -z "$_mail_subcommands" ]
  34. then
  35. # Cache the list of subcommands to speed things up.
  36. _mail_subcommands="$(mail --help 2> /dev/null \
  37. | grep '^ ' | cut -c 2-)"
  38. fi
  39. COMPREPLY=($(compgen -W "$_mail_subcommands" -- "$word_at_point"))
  40. ;;
  41. *)
  42. if _mail_is_command "neomutt" || _mail_is_command "inbox"
  43. then
  44. _mail_complete_available_addresses "$word_at_point"
  45. fi
  46. ;;
  47. esac
  48. }
  49. complete -F _mail_complete mail