Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blacklist program from bash completion

Fedora comes with "gstack" and a bunch of "gst-" programs which keep appearing in my bash completions when I'm trying to quickly type my git aliases. They're of course installed under /usr/bin along with a thousand other programs, so I can't just remove their directory from my PATH. Is there any way in Linux to blacklist these specific programs from appearing for completion?

I've tried the FIGNORE and GLOBIGNORE environment variables but they don't work, it looks like they're only for file completion after you've entered a command.

like image 831
Angus Avatar asked Jan 30 '15 20:01

Angus


2 Answers

In 2016 Bash introduced an option for that. I'm reproducing the text from this newer answer by zuazo:


This is rather new, but in Bash 4.4 you can set the EXECIGNORE variable:

aa. New variable: EXECIGNORE; a colon-separate list of patterns that will cause matching filenames to be ignored when searching for commands.

From the official documentation:

EXECIGNORE

A colon-separated list of shell patterns (see Pattern Matching) defining the list of filenames to be ignored by command search using PATH. Files whose full pathnames match one of these patterns are not considered executable files for the purposes of completion and command execution via PATH lookup. This does not affect the behavior of the [, test, and [[ commands. Full pathnames in the command hash table are not subject to EXECIGNORE. Use this variable to ignore shared library files that have the executable bit set, but are not executable files. The pattern matching honors the setting of the extglob shell option.

For Example:

$ EXECIGNORE=$(which pytest)

Or using Pattern Matching:

$ EXECIGNORE=*/pytest
like image 63
Helpfool Avatar answered Sep 21 '22 15:09

Helpfool


I don't know if you can blacklist specific files, but it is possible to complete from your command history instead of the path. To do that add the following line to ~/.inputrc:

TAB dynamic-complete-history

like image 34
ccarton Avatar answered Sep 19 '22 15:09

ccarton