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

zellij-completion #3869

Open
chuky2003 opened this issue Dec 14, 2024 · 0 comments
Open

zellij-completion #3869

chuky2003 opened this issue Dec 14, 2024 · 0 comments

Comments

@chuky2003
Copy link

chuky2003 commented Dec 14, 2024

I made a small bash script with ChatGPT that completes sessions, it would be nice to implement it

#!/bin/bash

_zellij_complete() {
    local cur prev opts subcommands sessions
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Opciones globales y subcomandos
    opts="-c --config --config-dir -d --debug --data-dir -h --help -l --layout --max-panes -n --new-session-with-layout -s --session -V --version"
    subcommands="action attach detach delete-all-sessions delete-session kill-all-sessions kill-session list-sessions run setup"

    # Obtener sesiones activas y eliminar caracteres ANSI
    sessions=$(zellij list-sessions 2>/dev/null | sed -E "s/\x1B\[[0-9;]*[mK]//g" | awk '{print $1}')

    if [[ "${prev}" == "zellij" ]]; then
        # Sugerir opciones globales y subcomandos
        COMPREPLY=( $(compgen -W "${opts} ${subcommands}" -- "${cur}") )
    elif [[ "${subcommands}" == *"${prev}"* ]]; then
        case "${prev}" in
            attach|detach|delete-session|kill-session)
                # Autocompletar nombres de sesión
                COMPREPLY=( $(compgen -W "${sessions}" -- "${cur}") )
                ;;
            action)
                # Autocompletar acciones disponibles (ampliar según necesidad)
                COMPREPLY=( $(compgen -W "focus-next-pane focus-previous-pane resize-up resize-down resize-left resize-right" -- "${cur}") )
                ;;
            run)
                # Autocompletar comandos disponibles en el sistema
                COMPREPLY=( $(compgen -c -- "${cur}") )
                ;;
            *)
                COMPREPLY=()
                ;;
        esac
    elif [[ "${opts}" == *"${prev}"* ]]; then
        case "${prev}" in
            --layout|-l|--new-session-with-layout)
                # Autocompletar archivos de layout (.kdl) desde la carpeta de configuraciones
                COMPREPLY=( $(compgen -W "$(find ~/.config/zellij/layouts/ -name '*.kdl' 2>/dev/null)" -- "${cur}") )
                ;;
            *)
                COMPREPLY=()
                ;;
        esac
    else
        COMPREPLY=()
    fi
}

complete -F _zellij_complete zellij
@chuky2003 chuky2003 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2024
@chuky2003 chuky2003 reopened this Dec 15, 2024
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