Skip to content

Explore different completion options #113

Description

@da-luce
  • Traditional _longopt Bash completion is probably simple and safer than current approach
  • This probably won't scale the 200k cities though, so we can leverage the binary for city completion:

I need to understand how bash completions work deeper, but here's an idea:

_astroterm_completions() {
    local cur prev
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # If the previous word was --city or -c, call the binary dynamically
    if [[ "$prev" == "--city" || "$prev" == "-c" ]]; then
        # Call the C program, pass the partial string, and map results to Bash
        local opts=$(astroterm --complete "$cur")
        COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
        return 0
    fi

    # Fallback to standard flags
    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $(compgen -W "--city --help --version" -- "$cur") )
        return 0
    fi
}
# Register the function
complete -F _astroterm_completions astroterm

No clue if this works though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions