Is it possible to copy the tab completion of a command for my linux function?

早过忘川 提交于 2019-12-23 22:28:53

问题


Let's say I have a bash shell function named magic. I want to define a tab completion function _magic which would allow magic to piggyback on the tab completion functions of any given command (if available). In other words, I want magic to be able to do something like this:

~ $ magic git ... <search for _git and use it if found>
~ $ magic cd ... <search for _cd and use it if found>
~ $ magic some-cmd ... <search for _some-cmd and use it if found>

I can't seem to find anything online that would help me achieve this using compgen, complete etc. Is this even possible? Thanks in advance.


回答1:


There are many such (pseudo?) commands, that need this. e.g. time, nice, strace etc.
They all use the same command completion: _command. So, don't re-invent the wheel. :)

Try running this in your bash terminal, if this work:

complete -F _command magic


来源:https://stackoverflow.com/questions/35353719/is-it-possible-to-copy-the-tab-completion-of-a-command-for-my-linux-function

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