coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

`uu_test` binary alias `[` causes issues for Zsh completions

Open manu-schaaf opened this issue 2 years ago • 3 comments

Issue

Using the Zsh completions of the coreutils binary created by running cargo run completion coreutils zsh results in an error:

coreutils _coreutils:1418: invalid subscript
_coreutils:1419: bad pattern: _coreutils__[_commands
_coreutils:23: bad pattern: [
_coreutils:23: bad pattern: [

Description

Creating completions using cargo run completion coreutils zsh will create completions for the uu_test create and thus both test and [ binaries as given here:

https://github.com/uutils/coreutils/blob/97d30bd486c8819d630cc864ee49a7edd16e3db1/build.rs#L60-L63

This results in a completions file containing the following:

  • lines 689-694
    ([)
    _arguments "${_arguments_options[@]}" \
    '-h[Print help]' \    
    '--help[Print help]' \
    && ret=0
    ;;
    
  • lines 1177-1180
    ([)
    _arguments "${_arguments_options[@]}" \
    && ret=0              
    ;;
    
  • lines 1418-1427
    (( $+functions[_coreutils__[_commands] )) ||
    _coreutils__[_commands() {
        local commands; commands=()
        _describe -t commands 'coreutils [ commands' commands "$@"
    }
    (( $+functions[_coreutils__help__[_commands] )) ||
    _coreutils__help__[_commands() {
        local commands; commands=()
        _describe -t commands 'coreutils help [ commands' commands "$@"
    }
    

Each of the snippets above contain invalid opening square brackets, resulting in the shown errors when using the generated completions in Zsh.

Workaround

Removing line 62 in build.rs fixes the issue: https://github.com/uutils/coreutils/blob/97d30bd486c8819d630cc864ee49a7edd16e3db1/build.rs#L62

Background

I installed the multicall binary from source and created the completions as given above, placing them in $FPATH. I am using Zsh 5.9.4 (with Oh My Zsh) on an Arch-based distro.

manu-schaaf avatar Nov 24 '23 11:11 manu-schaaf

We can't remove the [ alias there unfortunately, because we still need to support the alias, but we maybe we can skip generating completions for it? Alternatively, the [ should be an optional feature, since it is a built-in in zsh, so people can decide (based on their shell) whether they want it or not.

tertsdiepraam avatar Nov 24 '23 12:11 tertsdiepraam

or propose a fix in zsh :)

sylvestre avatar Nov 24 '23 12:11 sylvestre

I think it's intentional on zsh's side because [ is a built-in? Maybe not though

tertsdiepraam avatar Nov 24 '23 14:11 tertsdiepraam