Files
vns/_vns
2024-03-27 19:26:46 -05:00

73 lines
1.8 KiB
Plaintext

#compdef vns
#autoload
# Modified from _pass zsh completion, with the following copyright information
# Copyright (C) 2012 - 2014:
# Johan Venant <jvenant@invicem.pro>
# Brian Mattern <rephorm@rephorm.com>
# Jason A. Donenfeld <Jason@zx2c4.com>.
# All Rights Reserved.
# This file is licensed under the GPLv2+. Please see COPYING for more information.
_vns () {
local cmd
if (( CURRENT > 2)); then
cmd=${words[2]}
# Set the context for the subcommand.
curcontext="${curcontext%:*:*}:vns-$cmd"
# Narrow the range of words we are looking at to exclude `vns'
(( CURRENT-- ))
shift words
# Run the completion for the subcommand
case "${cmd}" in
-e|-p|-r|-d|-c)
_vns_complete_notes
;;
#-c)
# _vns_complete_notebooks
# ;;
-l)
_vns_complete_notes
;;
*)
if [ "${cmd[0]}" != '-' ] && (( CURRENT > 2)); then
_vns_complete_notebooks
fi
;;
esac
else
local -a subcommands
subcommands=(
"-c:Create note"
"-d:Delete note"
"-e:Edit note"
"-h:Display help message"
"-i:Import a note"
"-I:Initialize a new VNS store"
"-l:List notes"
"-m:Merge notes"
"-p:Print note to console"
"-r:Rename/move a note"
)
_describe -t commands 'vns' subcommands
_vns_complete_notebooks
fi
}
_vns_complete_entries_helper () {
local IFS=$'\n'
local prefix
zstyle -s ":completion:${curcontext}:" prefix prefix || prefix="${VNS_STORE_DIR:-$HOME/.vns}"
_values -C 'notes' ${$(find -L ${prefix} -mindepth 1 -name .git -prune -o $@ -print | sed -e "s#${prefix}/##" -e "s/.gpg//" -e "s#:#\\:#g" | sort):-""}
}
_vns_complete_notebooks () {
_vns_complete_entries_helper -type d
}
_vns_complete_notes () {
_vns_complete_entries_helper -type f
}
_vns