[Home] Zsh logo

_first

Zsh Wizard

Download _first Return to Examples
  1. #compdef -first-
  2. # Mail folder shortcuts - any command starting with "+" should be
  3. # a mail folder - complete only those which actually exist.
  4. if [[ "$compstate[context]" = command &&
  5. $CURRENT -eq 1 &&
  6. "$PREFIX" = +* ]]
  7. then
  8. local thisfolder thisentry expl ret=1
  9. local readmail unreadmail
  10. local mailstat
  11. readmail=( )
  12. unreadmail=( )
  13. mailstat=( )
  14. # Find each mailpath file that exists.
  15. for thisentry in "$mailpath[@]"
  16. do
  17. thisfolder="${thisentry%%\?*}"
  18. if [[ -s $thisfolder ]]
  19. then
  20. # Is it unread mail?
  21. # element 10 is mtime, element 9 is atime
  22. stat -A mailstat "$thisfolder"
  23. if [[ $mailstat[10] -gt $mailstat[9] ]]
  24. then
  25. unreadmail=("$unreadmail[@]" "${thisfolder##*/}")
  26. else
  27. readmail=("$readmail[@]" "${thisfolder##*/}")
  28. fi
  29. fi
  30. done
  31. if zsh-version 3.1.7
  32. then
  33. # Proper tag-handling completion.
  34. _tags -C mail-shortcuts unread-mail-folders read-mail-folders
  35. while _tags
  36. do
  37. _requested -J unread-mail-folders expl "unread mail" \
  38. compadd -P '+' -a unreadmail && ret=0
  39. _requested -J read-mail-folders expl "read mail" \
  40. compadd -P '+' -a readmail && ret=0
  41. (( ret )) || break
  42. done
  43. else
  44. # Just do regular compadds.
  45. compadd -P '+' -J "new mail folder" \
  46. -X "These folders contain new mail" \
  47. -- "${unreadmail[@]}"
  48. compadd -P '+' -J "mail folder" \
  49. -X "These folders contain mail" \
  50. -- "${readmail[@]}"
  51. fi
  52. # Skip all remaining completions.
  53. _compskip=all
  54. return 0
  55. fi