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

Also complete session names in generated zsh completions #3083

Open
cyruseuros opened this issue Jan 24, 2024 · 1 comment
Open

Also complete session names in generated zsh completions #3083

cyruseuros opened this issue Jan 24, 2024 · 1 comment

Comments

@cyruseuros
Copy link

Exactly like in #1030 - personally I've never written any custom zsh completions so unfortunately I can't contribute here.

@c60cb859
Copy link

c60cb859 commented Aug 5, 2024

I asked Claud to translate the comp.fish to zsh and I got this

# Function to list sessions
_zellij_list_sessions() {
    zellij list-sessions --short --no-formatting 2>/dev/null
}

# Function to list aliases
_zellij_list_aliases() {
    zellij list-aliases 2>/dev/null
}

# Zellij completions
_zellij() {
    local state

    _arguments \
        '1: :->command' \
        '*: :->args'

    case $state in
        command)
            _arguments '1:command:(attach a kill-session k setup)'
            ;;
        args)
            case ${words[2]} in
                attach|a|kill-session|k)
                    _alternative 'sessions:session:($(_zellij_list_sessions))'
                    ;;
                setup)
                    _arguments '*:option:((--generate-completion\:"Generate shell completion" bash\:"Bash" elvish\:"Elvish" fish\:"Fish" zsh\:"Zsh" powershell\:"PowerShell"))'
                    ;;
            esac
            ;;
    esac
}

compdef _zellij zellij

# Custom functions
zr() {
    command zellij run --name "$1" -- zsh -c "$*"
}

zrf() {
    command zellij run --name "$1" --floating -- zsh -c "$*"
}

zri() {
    command zellij run --name "$1" --in-place -- zsh -c "$*"
}

ze() {
    command zellij edit "$@"
}

zef() {
    command zellij edit --floating "$@"
}

zei() {
    command zellij edit --in-place "$@"
}

# zpipe function and its completions
zpipe() {
    if (( $# > 0 )); then
        command zellij pipe -p "$@"
    else
        command zellij pipe
    fi
}

_zpipe() {
    _alternative 'aliases:alias:($(_zellij_list_aliases))'
}

compdef _zpipe zpipe

this seem to work, but does make some of the stuff kind of ugly tho, and I dont know what it does

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

2 participants