Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elixir mix oh-my-zsh completion plugin

Elixir Mix Oh-My-Zsh plugin

Copy the folder ./elixir_mix/ to ~/.oh-my-zsh/custom/plugins/ and add _elixir_mix to your .zshrc plugins list. e.g.

Example:

plugins=(
  autojump
  git
  elixir_mix
)

#compdef mix
#autoload
# Elixir mix zsh completion
mix_help=$(mix --help \
| tr -s ' ' \
| sed -e 's/ # /:/' \
-e 's/^mix //' \
-e 's/^mix:.*//' \
-e 's/^iex.*//' )
declare -a all_tasks
all_tasks=($(echo $mix_help | sed 's/:.*//'))
local -a _1st_arguments
IFS=$'\n' _1st_arguments=($(mix_help))
_1st_arguments+=(
'--help:Describe available tasks'
'--version:Prints the Elixir version information'
)
__task_list ()
{
local expl
_wanted tasks expl 'help' compadd $all_tasks
}
local expl
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
':command:->command' \
'*::options:->options'
case $state in
(command)
_describe -t commands "mix subcommand" _1st_arguments
return
;;
(options)
case $line[1] in
(help)
_arguments ':feature:__task_list'
;;
(test)
_files
;;
esac
;;
esac
@jasonm23

This comment has been minimized.

Copy link
Owner Author

@jasonm23 jasonm23 commented Jul 21, 2016

Added as a pull request on oh-my-zsh (replaces the hardcoded completion task list in the current mix oh-my-zsh plugin.)

@Vayn

This comment has been minimized.

Copy link

@Vayn Vayn commented May 13, 2017

IFS=$'\n' _1st_arguments=($(mix_help)) should be
IFS=$'\n' _1st_arguments=($(echo $mix_help))

@eagle-te

This comment has been minimized.

Copy link

@eagle-te eagle-te commented May 20, 2019

@jasonm23
Would it be possible that you create a pull request for https://github.com/zsh-users/zsh-completions too?

tyvm

@jasonm23

This comment has been minimized.

Copy link
Owner Author

@jasonm23 jasonm23 commented May 20, 2019

@eagle-te feel free to use it, I haven't touched Elixir or Mix in 2 years so I think I'm not the right person to do this right now.

If you'd feel better if I attached and explicit Apache or MIT licence on this Gist I'm happy to do it.

@eagle-te

This comment has been minimized.

Copy link

@eagle-te eagle-te commented May 20, 2019

@jasonm23

Thanks,
no need to attach an extra licence.
I'll create a PR and credit you anyhow.

@jasonm23

This comment has been minimized.

Copy link
Owner Author

@jasonm23 jasonm23 commented May 21, 2019

Cheers

@justgage

This comment has been minimized.

Copy link

@justgage justgage commented Sep 10, 2020

This wasn't working for me so I fixed it in this gist: https://gist.github.com/justgage/1641a2d04a2e59169bac7902886d44c4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment