Nukesor / pueue

:stars: Manage your shell commands.
MIT License
4.69k stars 128 forks source link

generated completion script for bash generates a syntax error when sourced #488

Closed mcarifio closed 5 months ago

mcarifio commented 5 months ago

Describe the bug

First, ty for pueue. I can't use nushell without it.

The generated completion script for bash generates a syntax error when sourced. Details in the reproduction section.

Steps to reproduce

Installed pueue on fedora 39 via copr and generated a completion script with pueue completions bash /tmp/mcarifio-pueue-completions-lto/pueue.bash then sourced the generated file:

mcarifio@spider:~/.bashrc.d$p echo $BASH_VERSION
5.2.21(1)-release

mcarifio@spider:~/.bashrc.d$p pueue --version
Pueue client 3.0.0

mcarifio@spider:~/.bashrc.d$p cat /tmp/mcarifio-pueue-completions-lto/pueue.bash|head -n20
_pueue() {
    local i cur prev opts cmds
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    cmd=""
    opts=""

    for i in ${COMP_WORDS[@]}
    do
        case "${cmd},${i}" in
            ",$1")
                cmd="pueue"
                ;;
            Pueue client,add)
                cmd="Pueue client__add"
                ;;
            Pueue client,clean)
                cmd="Pueue client__clean"
                ;;

mcarifio@spider:~/.bashrc.d$p source /tmp/mcarifio-pueue-completions-lto/pueue.bash
-l: /tmp/mcarifio-pueue-completions-lto/pueue.bash: line 15: syntax error near unexpected token `client,add'
-l: /tmp/mcarifio-pueue-completions-lto/pueue.bash: line 15: `            Pueue client,add)'

Debug logs (if relevant)

No response

Operating system

Fedora Linux 39 (Workstation Edition)

Pueue version

3.0.0

Additional context

I think you may need to quote each matching constant e.g. ' Pueue client,add'). That's a guess.

Nukesor commented 5 months ago

Hey @mcarifio

Could you go ahead and double-check whether this also happens on the newest version? v3.0.0 is already more than a year old. This has been a notorious problem with clap-generate and they released quite a few fixes.

mcarifio commented 5 months ago

3.2 works

./pueue --version
pueue 3.2.0

mcarifio@spider:~/opt/pueue/current/bin$p echo $BASH_VERSION 
5.2.21(1)-release

mcarifio@spider:~/opt/pueue/current/bin$p ./pueue completions bash /tmp
mcarifio@spider:~/opt/pueue/current/bin$p source /tmp/pueue.bash 

ty