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

Bash completion emits error about invalid nosort option #5190

Closed
2 tasks done
gbelouze opened this issue Oct 30, 2023 · 8 comments · Fixed by #5278
Closed
2 tasks done

Bash completion emits error about invalid nosort option #5190

gbelouze opened this issue Oct 30, 2023 · 8 comments · Fixed by #5278
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies

Comments

@gbelouze
Copy link

Please complete the following tasks

Rust Version

rustc 1.73.0 (cc66ad468 2023-10-03)

Clap Version

ruff package version 0.0.292which specifies clap = { version = "4.4.7", features = ["derive"] }

Minimal reproducible code

not relevant

Steps to reproduce the bug with the above code

brew install ruff
and somewhere in your .bash_profile or .bashrc

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
fi

Actual Behaviour

When I open a new shell, the following error message is displayed

bash: complete: nosort: invalid option name

Expected Behaviour

No error message should be displayed.

Additional Context

Hello beautiful clap people. I come from this issue with the ruff package (plugin ? crate ? I'm not a rust person). I'll say here again the issue I described there :

  • am macOS user
  • use ruff (which relies on clap) installed through homebrew
  • use bash_completions for the installed homebrew packages (see Steps to reproduce above)
  • this triggers the issue
    Presumably, the issue is that the nosort option is supported starting from bash v4 only, while macOS still uses bash v3. See this comment by @zanieb which locates where this happens in clap.

I'm not sure if this is a bug or if clap is not trying to support old bash versions. Again I'm not a clap nor even a rust user.

Debug Output

No response

@gbelouze gbelouze added the C-bug Category: Updating dependencies label Oct 30, 2023
@epage epage added the A-completion Area: completion generator label Oct 30, 2023
@epage
Copy link
Member

epage commented Oct 30, 2023

Completions are mostly community maintained on a best-effort. If there is a reasonable way to skip nosort for bash v3 but to keep it for v4+, I'm willing to accept for it.

@gbelouze
Copy link
Author

Thanks for the quick response. The bash version is accessible with the ${BASH_VERSINFO[0]} variable. I'd wait for the input of someone who knows bash more than I do but I suppose something like

- complete -F _{name} -o nosort -o bashdefault -o default {name}
+ if [ ${BASH_VERSINFO[0]} -ge 4 ]; then
+     complete -F _{name} -o nosort -o bashdefault -o default {name}
+ else
+     complete -F _{name} -o bashdefault -o default {name}
+ fi

would be good enough.

@tavianator
Copy link

It was added in bash 4.4, checking >= 4 isn't enough

@epage
Copy link
Member

epage commented Nov 29, 2023

Whats the likelihood someone is using <4.4 who isn't on Mac and using v3?

@tavianator
Copy link

@epage I think CentOS 7 uses Bash 4.2, which is one of the platforms that led to sharkdp/fd#1407.

A fully correct check is not too hard, something like

major=${BASH_VERSINFO[0]}
minor=${BASH_VERSINFO[1]}
if ((major > 4 || (major == 4 && minor >= 4))); then
    complete -F _{name} -o nosort -o bashdefault -o default {name}
else
    complete -F _{name} -o bashdefault -o default {name}
fi

@mathomp4
Copy link

Whats the likelihood someone is using <4.4 who isn't on Mac and using v3?

FYI, I just hit this on a supercomputing cluster (via fd) which is rocking SLES12 and:

$ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

So, yeah, old OSs and old bashes live out there. Though I'm apparently right at the edge :)

(NOTE: Soon we will move to SLES15 and be closer to modern day.)

@epage
Copy link
Member

epage commented Dec 20, 2023

Ouch :) Enjoy the upgrade!

@epage
Copy link
Member

epage commented Dec 20, 2023

(btw to be clear, a PR fixing this from anyone would be welcome)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants