zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
20.65k stars 639 forks source link

Also complete session names in generated zsh completions #3083

Open cyruseuros opened 7 months ago

cyruseuros commented 7 months ago

Exactly like in https://github.com/zellij-org/zellij/issues/1030 - personally I've never written any custom zsh completions so unfortunately I can't contribute here.

c60cb859 commented 1 month ago

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