How can I provide tab completions to fish shell from my own script?

拈花ヽ惹草 提交于 2019-12-03 01:40:50
david.libremone

Adapted from zanchey's comment on GitHub:

If you have a program myprog which takes the --_completion option, you can write a single completion stub for myprog that looks like this:

complete --command myprog --arguments '(myprog --_completion (commandline -cp)'

Your program will then get invoked as myprog --_completion myprog some arguments here, and you can respond with the appropriate completions. It should return only the current token that is being completed (you could also pass this to the program with (commandline -ct), or tokenise it yourself), followed optionally by a tab and a short description. Multiple completions are separated with new lines.

Notes:

For Python scripts specifically, the following libraries may support fish completions at some point in the future (but they don't yet):

furins

You should create a fish autocomplete function for your script as proposed here and source it or put it inside your ~/.config/fish/completions folder.

reference: fish docs

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