Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom bash completions in zsh #13

Open
xatnight opened this issue May 24, 2024 · 0 comments
Open

Custom bash completions in zsh #13

xatnight opened this issue May 24, 2024 · 0 comments

Comments

@xatnight
Copy link

Hi! First off all, thanks for this wonderful script.

I'm currently in the process of migrating from oh-my-zsh to a setup with no plugin managers and I'm trying to learn how to setup my stuff, but I'm too stupid to make your script work with my custom bash completions.
With oh-my-zsh I would put my completion scripts into a folder that's included in my fpath and then autoload them into my .zshrc. For example for the binary kns it would look like this:

autoload -Uz _kns
autoload -U +X bashcompinit && bashcompinit
complete -F _kns kns

With zsh-bash-completions-fallback installed I thought I simply have to put the completion script into /usr/share/bash-completion/completions and be done but I think I'm missing something.

The script in question if it's needed (/usr/share/bash-completion/completions/_kns):

_kns() {
    if ! kubectl config current-context > /dev/null 2>&1 ; then
        return
    fi

    local cur="${COMP_WORDS[COMP_CWORD]}"
    if [[ ${cur} == -* || ${COMP_CWORD} -ne 1 ]]; then
        return
    fi

    local IFS=$'\n'
    local suggestions=$(kubectl get ns -o custom-columns=NAME:.metadata.name --no-headers)
    COMPREPLY=($(compgen -W "$suggestions" -- ${cur}))
}

complete -F _kns kns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant