diff --git a/completions/pass.zsh-completion b/completions/pass.zsh-completion new file mode 100644 index 0000000..cf99a4f --- /dev/null +++ b/completions/pass.zsh-completion @@ -0,0 +1,60 @@ +#compdef note +# +# Completion script for note +# + +_note () { + local cmd + if (( CURRENT > 2)); then + cmd=${words[2]} + curcontext="${curcontext%:*:*}:note-$cmd" + (( CURRENT-- )) + shift words + case "${cmd}" in + init) + ;; + find) + _note_complete_entries_with_subdirs + ;; + show|ls|list|edit) + _note_complete_entries_with_subdirs + ;; + cp|copy|mv|rename|rm) + _note_complete_entries_with_subdirs + ;; + esac + else + local -a subcommands + subcommands=( + "init:Initialize new note storage" + "ls:List note" + "find:Find note files or directories based on pattern" + "grep:Search note files for matching pattern" + "show:Print a note" + "edit:Edit a note with \$EDITOR" + "mv:Rename the note" + "cp:Copy the note" + "rm:Remove the note" + "version:Output version information" + "help:Output help message" + ) + _describe -t commands 'note' subcommands + fi +} + +_note_complete_entries_helper () { + local IFS=$'\n' + local notepath + zstyle -s ":completion:${curcontext}:" notepath notepath || notepath="${NOTE_STORE_DIR:-$HOME/.note-store}" + _values -C 'notes' ${$(find -L "$notepath" \( -name .git \) -prune -o $@ -print 2>/dev/null | sed -e "s#${notepath}/\{0,1\}##" -e 's#\.md##' -e 's#\\#\\\\#g' -e 's#:#\\:#g' | sort):-""} +} + +_note_complete_entries_with_subdirs () { + _note_complete_entries_helper +} + +_note_complete_entries () { + _note_complete_entries_helper -type f +} + +_note \ No newline at end of file