问题
Is there a way how to control completion for first command being typed on bash4 command prompt?
I can control completions for "empty line" with complete -E, but as soon as some characters are typed, bash (or possibly readline) gives me all filenames from PATH, builtin commands (if, then, else...) and functions on completion attempt (TAB).
I was able to avoid PATH entries by unsetting PATH in PROMPT_COMMAND and restoring it by binding function to trap DEBUG, but no luck with getting rid of bash bultin commands completions.
Any ideas?
回答1:
This is a veritable weak point in the design of bash's programmable completion facilities. Even the “default” command completion -D
takes effect for commands on a blank line only (provided that no complete -E
is specified). Something like complete -I
(for incompletely typed-in commands) is missing.
回答2:
bash completions are stored in /etc/bash_completion.d/ If you have root access, then you could edit/delete files there.
If you want to control things at the user level, then you could create and edit ~/.inputrc. Have a look at /etc/inputrc and it will give you an idea of where to start.
~/.inputrc overrides anything in /etc/inputrc, so you could change the places where bash_completion looks for completion files. You could make a local completion directory and have only the items you want completed in there. I believe you can also eliminate bash built-ins also.
There are also a couple of very good tutorials on bash completion online. Here Here
来源:https://stackoverflow.com/questions/10450289/bash-programmable-completion-when-typing-first-command