Stack: [Shell autocompletion] autocompletion setup does not work in ZSH

Created on 14 Jun 2015  Â·  7Comments  Â·  Source: commercialhaskell/stack

stack autocompletion setup does not work in zsh:

➜ eval "$(stack --bash-completion-script "$(which stack)")"
zsh: command not found: complete

On bash (same machine, same user), it works

documentation

Most helpful comment

  • Is text below ok to be added to the wiki ?
  • should we add a subcommand stack autocomple displaying enough information for newcomers to discover and setup autocompletion from here ?

Shell Autocompletion:

for ZSH users:

documentation says:

Zsh can handle bash completions functions. The latest development version of zsh has a function bashcompinit, that when run will allow zsh to read bash completion specifications and functions. This is documented in the zshcompsys man page. To use it all you need to do is run bashcompinit at any time after compinit. It will define complete and compgen functions corresponding to the bash builtins.

You must so:

  1. launch compinint
  2. launch bashcompinit
  3. eval stack bash completion script
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
source /path/to/your/bash_completion_script

:information_source: If you already have quite a large zshrc, or if you use oh-my-zsh, compinit will probably already be loaded. If you have a blank zsh config, all of the 3 lines above are necessary.

:gem: tip: instead of running those 3 lines from your shell every time you want to use stack, you can add those 3 lines in your $HOME/.zshrc file

All 7 comments

I had the same problem, but found the solution was to load the bashcompinit module

λ church ~ → eval "$(stack --bash-completion-script "$(which stack)")"
zsh: command not found: complete
λ church ~ → autoload bashcompinit
λ church ~ → bashcompinit
λ church ~ → eval "$(stack --bash-completion-script "$(which stack)")"
λ church ~ → stack
bench             docker/           ghc               --help            --no-install-ghc  runghc            test              -v                --version                                         
build/            --docker*         ghci              install           --no-system-ghc   setup             unpack            --verbose                                                         
clean             exec              haddock           --install-ghc     path              --system-ghc      update            --verbosity                                                       

@rvion Would you be able to update the documentation to clarify this requirement for zsh users?

  • Is text below ok to be added to the wiki ?
  • should we add a subcommand stack autocomple displaying enough information for newcomers to discover and setup autocompletion from here ?

Shell Autocompletion:

for ZSH users:

documentation says:

Zsh can handle bash completions functions. The latest development version of zsh has a function bashcompinit, that when run will allow zsh to read bash completion specifications and functions. This is documented in the zshcompsys man page. To use it all you need to do is run bashcompinit at any time after compinit. It will define complete and compgen functions corresponding to the bash builtins.

You must so:

  1. launch compinint
  2. launch bashcompinit
  3. eval stack bash completion script
autoload -U +X compinit && compinit
autoload -U +X bashcompinit && bashcompinit
source /path/to/your/bash_completion_script

:information_source: If you already have quite a large zshrc, or if you use oh-my-zsh, compinit will probably already be loaded. If you have a blank zsh config, all of the 3 lines above are necessary.

:gem: tip: instead of running those 3 lines from your shell every time you want to use stack, you can add those 3 lines in your $HOME/.zshrc file

Looks good. I'm at about -0.5 on adding a command to stack for this, since our --help output is already becoming a bit intimidating. But I could be swayed otherwise.

I'm creating an other specific page in the wiki not to pollute the FAQ, and will link the new page from here.
Current state makes it too hard to discover the feature (I had to search over the 10 pages wiki to find it)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jwaldmann picture jwaldmann  Â·  4Comments

domenkozar picture domenkozar  Â·  3Comments

symbiont-joseph-kachmar picture symbiont-joseph-kachmar  Â·  3Comments

srghma picture srghma  Â·  3Comments

Cosmius picture Cosmius  Â·  3Comments