5f18dbf895675ff22dcbe2afa78b72b74350ea58

Author
Sung Won Cho <hello@sung.io>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Add a completion plugin for dnote (#7885)

Diff

  1diff --git a/plugins/dnote/README.md b/plugins/dnote/README.md
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..e1b9b7044970d56330c08c6231b807e3bcbf62d5
  4--- /dev/null
  5+++ b/plugins/dnote/README.md
  6@@ -0,0 +1,51 @@
  7+# Dnote Plugin
  8+
  9+This plugin adds auto-completion for [Dnote](https://dnote.io) project.
 10+
 11+To use it, add `dnote` to the plugins array in your zshrc file:
 12+
 13+```zsh
 14+plugins=(dnote)
 15+```
 16+
 17+## Usage
 18+
 19+At the basic level, this plugin completes all Dnote commands.
 20+
 21+```zsh
 22+$ dnote a(press <TAB> here)
 23+```
 24+
 25+would result in:
 26+
 27+```zsh
 28+$ dnote add
 29+```
 30+
 31+For some commands, this plugin dynamically suggests matching book names.
 32+
 33+For instance, if you have three books that begin with 'j': 'javascript', 'job', 'js',
 34+
 35+```zsh
 36+$ dnote view j(press <TAB> here)
 37+```
 38+
 39+would result in:
 40+
 41+```zsh
 42+$ dnote v j
 43+javascript  job         js
 44+```
 45+
 46+As another example,
 47+
 48+```zsh
 49+$ dnote edit ja(press <TAB> here)
 50+```
 51+
 52+would result in:
 53+
 54+
 55+```zsh
 56+$ dnote v javascript
 57+``````
 58diff --git a/plugins/dnote/_dnote b/plugins/dnote/_dnote
 59new file mode 100644
 60index 0000000000000000000000000000000000000000..c8b33486a370e9db3412605589e1a6267bd9188c
 61--- /dev/null
 62+++ b/plugins/dnote/_dnote
 63@@ -0,0 +1,39 @@
 64+#compdef dnote
 65+
 66+local -a _1st_arguments
 67+
 68+_1st_arguments=(
 69+  'add:add a new note'
 70+  'view:list books, notes, or view a content'
 71+  'edit:edit a note or a book'
 72+  'remove:remove a note or a book'
 73+  'find:find notes by keywords'
 74+  'sync:sync data with the server'
 75+  'login:login to the dnote server'
 76+  'logout:logout from the dnote server'
 77+  'version:print the current version'
 78+  'help:get help about any command'
 79+)
 80+
 81+get_booknames() {
 82+  local names=$(dnote view --name-only)
 83+  local -a ret
 84+
 85+  while read -r line; do
 86+    ret+=("${line}")
 87+  done <<< "$names"
 88+
 89+  echo "$ret"
 90+}
 91+
 92+if (( CURRENT == 2 )); then
 93+  _describe -t commands "dnote subcommand" _1st_arguments
 94+  return
 95+elif (( CURRENT == 3 )); then
 96+  case "$words[2]" in
 97+    v|view|a|add)
 98+      _alternative \
 99+        "names:book names:($(get_booknames))"
100+  esac
101+fi
102+