_dnote 814 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #compdef dnote
  2. local -a _1st_arguments
  3. _1st_arguments=(
  4. 'add:add a new note'
  5. 'view:list books, notes, or view a content'
  6. 'edit:edit a note or a book'
  7. 'remove:remove a note or a book'
  8. 'find:find notes by keywords'
  9. 'sync:sync data with the server'
  10. 'login:login to the dnote server'
  11. 'logout:logout from the dnote server'
  12. 'version:print the current version'
  13. 'help:get help about any command'
  14. )
  15. get_booknames() {
  16. local names=$(dnote view --name-only)
  17. local -a ret
  18. while read -r line; do
  19. ret+=("${line}")
  20. done <<< "$names"
  21. echo "$ret"
  22. }
  23. if (( CURRENT == 2 )); then
  24. _describe -t commands "dnote subcommand" _1st_arguments
  25. return
  26. elif (( CURRENT == 3 )); then
  27. case "$words[2]" in
  28. v|view|a|add)
  29. _alternative \
  30. "names:book names:($(get_booknames))"
  31. esac
  32. fi