#compdef note local file_name_comp='*: :_files -W ${NOTES_DIR} -g "*.norg(:r)" -S " "' (( $+functions[_Note_subcommand] )) || _Note_command() { local -a args args=( {--open,-o}'[Create or edit a note]' {--delete,-d}'[Delete a note]' {--list,-l}'[List all notes]' "${file_name_comp}" ) _arguments -S -s $args } if (( ${#words} == 2 )); then _Note_command elif (( ${#words} == 3)); then _arguments "${file_name_comp}" elif (( ${#words} > 3 )) && [[ ${words[2]} = "--delete" || ${words[2]} = "-d" ]]; then _arguments "${file_name_comp}" fi