0

This is kind of the opposite of this question.

I used to use ag to search for text in my projects, but then I found the hyperlinked grep from kitty. So I ripped out that script from kitty, dropped it in my user's bin, and aliased ag in my shell to run the script.

But now I've noticed that, because my alias is ag, Bash is loading the shell completion code for the real /usr/bin/ag and using it to try and complete commands that start with my ag alias. But the shell completion code actually executes ag on every completion attempt, and expects whatever ag points to in the shell to support a --list-file-types option, which the real /usr/bin/ag does, but which the script I use (which eventually delegates to rg AKA ripgrep) doesn't support. So when I type a, g, <TAB>, I get this printed:

ag error: Found argument '--list-file-types' which wasn't expected, or isn't valid in this context

USAGE:
    
    rg [OPTIONS] PATTERN [PATH ...]
    rg [OPTIONS] [-e PATTERN ...] [-f PATTERNFILE ...] [PATH ...]
    rg [OPTIONS] --files [PATH ...]
    rg [OPTIONS] --type-list
    command | rg [OPTIONS] PATTERN

For more information try --help

If I do complete -p | grep ag I see that it has loaded a completion function for ag:

complete -F _ag ag

If I complete -r ag I can unload the rule. But then if I do a, g, <TAB> again, the machinery responsible for dynamically loading completion rules sees that there's completion rules available for ag at /usr/share/bash-completion/completions/ag, and that no completion for ag is crrently set, so it re-loads them.

How do I stop my shell from using the available completion rules at /usr/share/bash-completion/completions/ag on my alias ag that does not actually correspond to those rules?

I really would like a method that 1. doesn't require uninstalling ag or its rules at the system level (so it can work for a non-superuser), and 2. doesn't require loading a fake completion rule to take the place of the system-provided one (although if that's the only way to do it I would like to know how to do that). I would also still like autocompletion to work for the ag command, using the default autocompletion behavior for commands and executables that don't have any special rules defined (which seems to be to just suggest filenames).

I noticed that /usr/share/bash-completion/bash_completion (which seems to be version 2.10 of https://github.com/scop/bash-completion on my system) has an internal _blacklist_glob; is there some way to control that as a user to ban a certain completion rule?

interfect
  • 2,665
  • 1
  • 20
  • 35

0 Answers0