Skip to content

Instantly share code, notes, and snippets.

@supermario
Last active May 27, 2018 13:53
Show Gist options
  • Save supermario/fa2aa52fe00d9182f9052be9d49ce354 to your computer and use it in GitHub Desktop.
Save supermario/fa2aa52fe00d9182f9052be9d49ce354 to your computer and use it in GitHub Desktop.
elm-zsh-autocomplete

Current state of zsh integration

With a basic integration relying only on elm autocomplete N ..., this is what it looks like:

https://asciinema.org/a/TjAxDkyJN4Si8ToFUv7sjRe09

  • Auto-suggestions are layed out horizontally
  • Sub-params are also detected and layed out

This is a reasonable first step, it works ok.

What would be nicer

Here's what the bower plugin output looks like:

https://asciinema.org/a/W4UUTnzU1a3ZFd6nrs58tSRO5

  • All the commands have descriptions so they're layed out vertially
  • Sub-params are contextual with descriptions as well if more than one applies (as seen with bower install)

From what I could find this appears to be the extent to which zsh autocomplete makes available out of the box, without installing further plguins.

Documentation

On even better autocomplete of argument values

I tried reading through the ZSH autocompletion docs to figure out if it was possible – but I didn't have enough time and this is well past my limited knowledge in this domain

I also went through a lot of the oh-my-zsh catalogue of plugins, and as far as I could see, none of the utilities I know well (I looked at bower, heroku, stack, cabal, ruby, rails) had anything covering both params (--port) and values (8080) in autocompletion together.

On Fish-like autocomplete

On top of this, I discovered that https://github.com/zsh-users/zsh-autosuggestions is a very popular plugin, that provides " Fish-like fast/unobtrusive autosuggestions for zsh."

This is the effect it produces as per their readme: https://asciinema.org/a/37390

However it does not seem to fundamentally change the auto-suggest, just provides an inline/live display of it like fish – which maybe not all zsh users prefer.

Install/enable steps

With oh-my-zsh package manager

  • Create ~/.oh-my-zsh/custom/plugins/elm/elm.plugin.zsh with the contents of elm.plugin.zsh
  • Edit ~/.zshrc and append elm to plugins
    • i.e. plugins=(x y z) -> plugins=(x y z elm)
    • Here is a one-shot command that adds elm only if it doesn't already exist (only tested on OS X)
    • sed -i -- '/elm/! s/^plugins=(\(.*\))/plugins=(\1 elm)/g' ~/.zshrc
  • Reload zsh
    • . ~/.zshrc

With vanilla zsh

There does not appear to be any standard folder for zsh config – only the ~/.zshrc and /etc/zshrc files.

  • Create ~/.elm.plugin.zsh (?) with the contents of elm.plugin.zsh
  • Edit ~/.zshrc and add source ~/.elm.plugin.zsh
    • Here is a one-shot command that adds this only if it doesn't already exist (only tested on OS X)
    • grep "elm.plugin.zsh" ~/.zshrc || echo "source ~/.elm.plugin.zsh" >> ~/.zshrc
  • Reload zsh
    • . ~/.zshrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment