Make zsh complete arguments from a file

后端 未结 2 538
醉话见心
醉话见心 2021-02-03 12:33

zsh is great but its completion system is very diverse. And the documentation lacks good examples. Is there a template for completing for a specific application. Th

2条回答
  •  爱一瞬间的悲伤
    2021-02-03 13:17

    Without changing anything further in .zshrc (I already have autoload -Uz compinit compinit) I added the following as /usr/local/share/zsh/site-functions/_drush

    #compdef drush
    _arguments "1: :($(/usr/local/bin/aliases-drush.php))"
    

    Where /usr/local/bin/aliases-drush.php just prints a list of strings, each string being a potential first argument for the command drush. You could use ($(< filename)) to complete from filename.

    I based this on https://unix.stackexchange.com/a/458850/9452 -- it's surprising how simple this is at the end of the day.

提交回复
热议问题