#compdef bkmr

autoload -U is-at-least

_bkmr() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-c+[Sets a custom config file]:FILE:_files' \
'--config=[Sets a custom config file]:FILE:_files' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'*-d[Turn debugging information on (-d=info, -dd=debug, -ddd=trace)]' \
'*--debug[Turn debugging information on (-d=info, -dd=debug, -ddd=trace)]' \
'--no-color[Disable colored output]' \
'--generate-config[bkmr --generate-config > ~/.config/bkmr/config.toml]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::name -- Optional name to operate on:_default' \
":: :_bkmr_commands" \
"*::: :->bkmr" \
&& ret=0
    case $state in
    (bkmr)
        words=($line[2] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:bkmr-command-$line[2]:"
        case $line[2] in
            (search)
_arguments "${_arguments_options[@]}" : \
'-e+[exact tag match (comma-separated)]:TAGS_EXACT:_default' \
'--exact=[exact tag match (comma-separated)]:TAGS_EXACT:_default' \
'--exact-prefix=[prefix tags combined with --exact]:TAGS_EXACT_PREFIX:_default' \
'-t+[must have ALL these tags (comma-separated)]:TAGS_ALL:_default' \
'--tags=[must have ALL these tags (comma-separated)]:TAGS_ALL:_default' \
'--tags-prefix=[prefix tags combined with --tags]:TAGS_ALL_PREFIX:_default' \
'-T+[exclude if has ALL these tags (comma-separated)]:TAGS_ALL_NOT:_default' \
'--Tags=[exclude if has ALL these tags (comma-separated)]:TAGS_ALL_NOT:_default' \
'--Tags-prefix=[prefix tags combined with --Tags]:TAGS_ALL_NOT_PREFIX:_default' \
'-n+[must have ANY of these tags (comma-separated)]:TAGS_ANY:_default' \
'--ntags=[must have ANY of these tags (comma-separated)]:TAGS_ANY:_default' \
'--ntags-prefix=[prefix tags combined with --ntags]:TAGS_ANY_PREFIX:_default' \
'-N+[exclude if has ANY of these tags (comma-separated)]:TAGS_ANY_NOT:_default' \
'--Ntags=[exclude if has ANY of these tags (comma-separated)]:TAGS_ANY_NOT:_default' \
'--Ntags-prefix=[prefix tags combined with --Ntags]:TAGS_ANY_NOT_PREFIX:_default' \
'--sort=[sort field\: id, title, modified (default\: id). Without -o/-O, id/title default ascending, modified defaults descending]:SORT_FIELD:_default' \
'--fzf-style=[fuzzy finder style\: classic or enhanced]:FZF_STYLE:_default' \
'-l+[limit number of results]:LIMIT:_default' \
'--limit=[limit number of results]:LIMIT:_default' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'-o[sort descending (implies --sort modified if no --sort given)]' \
'--descending[sort descending (implies --sort modified if no --sort given)]' \
'-O[sort ascending (implies --sort modified if no --sort given)]' \
'--ascending[sort ascending (implies --sort modified if no --sort given)]' \
'--np[no prompt]' \
'--fzf[use fuzzy finder\: \[CTRL-O\: copy to clipboard (shell scripts\: copy '\''bkmr open --no-edit <id> --'\'' command), CTRL-E\: edit, CTRL-D\: delete, CTRL-A\: clone, CTRL-P\: show details, ENTER\: open\]]' \
'--json[non-interactive mode, output as json]' \
'--interpolate[process template interpolation in search results display (not needed for FZF mode or bookmark actions - they interpolate automatically)]' \
'--shell-stubs[output shell function stubs for shell script bookmarks (automatically filters for _shell_ type)]' \
'--stdout[output selected bookmark content to stdout instead of executing (for shell wrapper integration)]' \
'--embeddable[filter to show only embeddable bookmarks]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
'::fts_query -- FTS query (full text search):_default' \
&& ret=0
;;
(hsearch)
_arguments "${_arguments_options[@]}" : \
'-t+[must have ALL these tags (comma-separated)]:TAGS_ALL:_default' \
'--tags=[must have ALL these tags (comma-separated)]:TAGS_ALL:_default' \
'-T+[exclude if has ALL these tags (comma-separated)]:TAGS_ALL_NOT:_default' \
'--Tags=[exclude if has ALL these tags (comma-separated)]:TAGS_ALL_NOT:_default' \
'-n+[must have ANY of these tags (comma-separated)]:TAGS_ANY:_default' \
'--ntags=[must have ANY of these tags (comma-separated)]:TAGS_ANY:_default' \
'-N+[exclude if has ANY of these tags (comma-separated)]:TAGS_ANY_NOT:_default' \
'--Ntags=[exclude if has ANY of these tags (comma-separated)]:TAGS_ANY_NOT:_default' \
'-e+[exact tag match (comma-separated)]:TAGS_EXACT:_default' \
'--exact=[exact tag match (comma-separated)]:TAGS_EXACT:_default' \
'--mode=[search mode\: hybrid or exact]:MODE:_default' \
'-l+[limit number of results]:LIMIT:_default' \
'--limit=[limit number of results]:LIMIT:_default' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--json[output as JSON (includes rrf_score)]' \
'--fzf[use fzf for interactive selection]' \
'--stdout[output to stdout for piping]' \
'--np[no prompt]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':query -- Search query text:_default' \
&& ret=0
;;
(sem-search)
_arguments "${_arguments_options[@]}" : \
'-l+[limit number of results]:LIMIT:_default' \
'--limit=[limit number of results]:LIMIT:_default' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--np[no prompt]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':query -- Search query (natural language):_default' \
&& ret=0
;;
(open)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-edit[skip interactive editing for shell scripts]' \
'--file[treat ids parameter as file path for direct viewing]' \
'--stdout[output bookmark content to stdout instead of executing]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':ids -- Bookmark IDs (comma-separated) or file path with --file:_default' \
'*::script_args -- Arguments to pass to shell scripts (use -- to separate\: bkmr open ID -- arg1 arg2):_default' \
&& ret=0
;;
(add)
_arguments "${_arguments_options[@]}" : \
'--title=[bookmark title]:TITLE:_default' \
'-d+[bookmark description]:DESC:_default' \
'--description=[bookmark description]:DESC:_default' \
'-t+[bookmark type (uri, snip, text, shell, md, env)]:BOOKMARK_TYPE:_default' \
'--type=[bookmark type (uri, snip, text, shell, md, env)]:BOOKMARK_TYPE:_default' \
'-c+[clone an existing bookmark by ID]:CLONE_ID:_default' \
'--clone=[clone an existing bookmark by ID]:CLONE_ID:_default' \
'--open-with=[custom command to open this bookmark (replaces default open behavior)]:OPEN_WITH:_default' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-web[do not fetch URL data]' \
'-e[edit the bookmark while adding]' \
'--edit[edit the bookmark while adding]' \
'--stdin[read content from stdin into url field]' \
'--no-embed[do not generate embedding for semantic search]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
'::url -- URL or content to store:_default' \
'::tags -- Tags (comma-separated, no spaces):_default' \
&& ret=0
;;
(delete)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':ids -- Bookmark IDs (comma-separated):_default' \
&& ret=0
;;
(update)
_arguments "${_arguments_options[@]}" : \
'-t+[add tags to taglist]:TAGS:_default' \
'--tags=[add tags to taglist]:TAGS:_default' \
'-n+[remove tags from taglist]:TAGS_NOT:_default' \
'--ntags=[remove tags from taglist]:TAGS_NOT:_default' \
'--title=[set bookmark title]:TITLE:_default' \
'-d+[set bookmark description]:DESCRIPTION:_default' \
'--description=[set bookmark description]:DESCRIPTION:_default' \
'--url=[set bookmark URL/content]:URL:_default' \
'--open-with=[set custom command to open this bookmark (use empty string to clear)]:OPEN_WITH:_default' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'-f[overwrite taglist with tags]' \
'--force[overwrite taglist with tags]' \
'--embed[enable embedding for semantic search]' \
'--no-embed[disable embedding for semantic search]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':ids -- Bookmark IDs (comma-separated):_default' \
&& ret=0
;;
(edit)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--force-db[force edit database content instead of source file for file-imported bookmarks]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':ids -- Bookmark IDs (comma-separated):_default' \
&& ret=0
;;
(show)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--json[output as JSON]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':ids -- Bookmark IDs (comma-separated):_default' \
&& ret=0
;;
(surprise)
_arguments "${_arguments_options[@]}" : \
'-n+[number of URLs to open]:N:_default' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(tags)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
'::tag -- Show tags related to this tag (omit to list all):_default' \
&& ret=0
;;
(create-db)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--pre-fill[Pre-fill the database with demo entries]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
'::path -- Path where the database will be created (default\: ~/.config/bkmr/bkmr.db):_default' \
&& ret=0
;;
(backfill)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'-d[only show what would be done]' \
'--dry-run[only show what would be done]' \
'-f[force recompute of all embeddings (except _imported_)]' \
'--force[force recompute of all embeddings (except _imported_)]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(clear-embeddings)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(load-json)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'-d[only show what would be done]' \
'--dry-run[only show what would be done]' \
'--no-embed[do not generate embedding for semantic search]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':path -- Path to JSON file with an array of bookmark objects:_default' \
&& ret=0
;;
(import-files)
_arguments "${_arguments_options[@]}" : \
'--base-path=[Base path variable name from config (e.g., SCRIPTS_HOME). Paths must be relative to the base path location.]:BASE_PATH:_default' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'-u[Update existing bookmarks when content differs]' \
'--update[Update existing bookmarks when content differs]' \
'--delete-missing[Delete bookmarks whose source files no longer exist]' \
'-d[Show what would be done without making changes]' \
'--dry-run[Show what would be done without making changes]' \
'-v[Show detailed information about skipped files and validation issues]' \
'--verbose[Show detailed information about skipped files and validation issues]' \
'--no-embed[do not generate embedding for semantic search]' \
'--no-color[Disable colored output]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'*::paths -- Directories or files to import:_default' \
&& ret=0
;;
(info)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'-s[Show database schema]' \
'--schema[Show database schema]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(completion)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':shell -- Shell to generate completions for (bash, zsh, fish):_default' \
&& ret=0
;;
(lsp)
_arguments "${_arguments_options[@]}" : \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-interpolation[Disable bkmr template interpolation]' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(xxx)
_arguments "${_arguments_options[@]}" : \
'-t+[add tags to taglist]:TAGS:_default' \
'--tags=[add tags to taglist]:TAGS:_default' \
'--db=[Path to database file (overrides BKMR_DB_URL and config.toml)]:FILE:_files' \
'--no-color[Disable colored output]' \
'-h[Print help]' \
'--help[Print help]' \
':ids -- list of ids, separated by comma, no blanks:_default' \
&& ret=0
;;
        esac
    ;;
esac
}

(( $+functions[_bkmr_commands] )) ||
_bkmr_commands() {
    local commands; commands=(
'search:Search bookmarks with full-text search and tag filters' \
'hsearch:Hybrid search combining full-text and semantic search with RRF fusion' \
'sem-search:Semantic search using embeddings only' \
'open:Open bookmark (smart action based on content type)' \
'add:Add a bookmark' \
'delete:Delete bookmarks by ID' \
'update:Update bookmark fields non-interactively (tags, title, description, URL, opener)' \
'edit:Edit bookmarks interactively in \$EDITOR (smart\: opens source file for imports)' \
'show:Show bookmark details' \
'surprise:Open random bookmarks for serendipitous discovery' \
'tags:List all tags (or show related tags for a given tag)' \
'create-db:Initialize bookmark database' \
'backfill:Generate missing embeddings for embeddable bookmarks' \
'clear-embeddings:Clear all embeddings and content hashes (clean slate for backfill)' \
'load-json:Bulk-create bookmarks from JSON array (skips existing Content/URLs, no update support)' \
'import-files:Import files from directories (stores content, tracks source file for smart editing)' \
'info:Show program information and configuration details' \
'completion:Generate shell completions for bash, zsh, or fish' \
'lsp:Start LSP server for editor snippet completion (VS Code, Neovim, IntelliJ)' \
'xxx:' \
    )
    _describe -t commands 'bkmr commands' commands "$@"
}
(( $+functions[_bkmr__add_commands] )) ||
_bkmr__add_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr add commands' commands "$@"
}
(( $+functions[_bkmr__backfill_commands] )) ||
_bkmr__backfill_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr backfill commands' commands "$@"
}
(( $+functions[_bkmr__clear-embeddings_commands] )) ||
_bkmr__clear-embeddings_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr clear-embeddings commands' commands "$@"
}
(( $+functions[_bkmr__completion_commands] )) ||
_bkmr__completion_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr completion commands' commands "$@"
}
(( $+functions[_bkmr__create-db_commands] )) ||
_bkmr__create-db_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr create-db commands' commands "$@"
}
(( $+functions[_bkmr__delete_commands] )) ||
_bkmr__delete_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr delete commands' commands "$@"
}
(( $+functions[_bkmr__edit_commands] )) ||
_bkmr__edit_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr edit commands' commands "$@"
}
(( $+functions[_bkmr__hsearch_commands] )) ||
_bkmr__hsearch_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr hsearch commands' commands "$@"
}
(( $+functions[_bkmr__import-files_commands] )) ||
_bkmr__import-files_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr import-files commands' commands "$@"
}
(( $+functions[_bkmr__info_commands] )) ||
_bkmr__info_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr info commands' commands "$@"
}
(( $+functions[_bkmr__load-json_commands] )) ||
_bkmr__load-json_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr load-json commands' commands "$@"
}
(( $+functions[_bkmr__lsp_commands] )) ||
_bkmr__lsp_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr lsp commands' commands "$@"
}
(( $+functions[_bkmr__open_commands] )) ||
_bkmr__open_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr open commands' commands "$@"
}
(( $+functions[_bkmr__search_commands] )) ||
_bkmr__search_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr search commands' commands "$@"
}
(( $+functions[_bkmr__sem-search_commands] )) ||
_bkmr__sem-search_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr sem-search commands' commands "$@"
}
(( $+functions[_bkmr__show_commands] )) ||
_bkmr__show_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr show commands' commands "$@"
}
(( $+functions[_bkmr__surprise_commands] )) ||
_bkmr__surprise_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr surprise commands' commands "$@"
}
(( $+functions[_bkmr__tags_commands] )) ||
_bkmr__tags_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr tags commands' commands "$@"
}
(( $+functions[_bkmr__update_commands] )) ||
_bkmr__update_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr update commands' commands "$@"
}
(( $+functions[_bkmr__xxx_commands] )) ||
_bkmr__xxx_commands() {
    local commands; commands=()
    _describe -t commands 'bkmr xxx commands' commands "$@"
}

if [ "$funcstack[1]" = "_bkmr" ]; then
    _bkmr "$@"
else
    compdef _bkmr bkmr
fi
