Bash programmable completion when typing “first command”

感情迁移 提交于 2020-07-06 12:26:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!