Issue
How do I remove a single "command" from Bash's auto complete command suggestions? I'm asking about the very first argument, the command, in auto complete, not asking "href="https://unix.stackexchange.com/questions/96534/disable-bash-autocompletion-for-a-specific-command-only">How to disable bash autocomplete for the arguments of a specific command"
For example, if I have the command ls
and the system path also finds ls_not_the_one_I_want_ever
, and I type ls
and then press tab, I want a way to have removed ls_not_the_one_I_want_ever
from every being a viable option.
I think this might be related to the compgen -c
list, as this seems to be the list of commands available.
Background: WSL on Windows is putting all the .dll
files on my path, in addition to the .exe
files that should be there, and so I have many dlls I would like to remove in my bash environment, but I'm unsure how to proceed.
Solution
Bash 5.0's complete
command added a new -I
option for this.
According to man bash
—
complete -pr [-DEI] [name ...]
[...] The
-I
option indicates that other supplied options and actions should apply to completion on the initial non-assignment word on the line, or after a command delimiter such as;
or|
, which is usually command name completion. [...]
Example:
function _comp_commands()
{
local cur=$2
if [[ $cur == ls* ]]; then
COMPREPLY=( $(compgen -c "$cur" | grep -v ls_not_wanted) )
fi
}
complete -o bashdefault -I -F _comp_commands
Answered By - pynexj Answer Checked By - Senaida (WPSolving Volunteer)