ohmyzsh/plugins/mix/_mix
Justin Puah 39b0bf20f2 Dynamic generation of mix commands for zsh completion.
I wrote my own zsh completion file for mix today. I realised that depending on the project the mix tasks can change because of dependencies like phoenix or ecto.
E.g. usually you wouldn't have 'mix phoenix.server' except in the project directory for a phoenix web app.
This is my solution for "dynamic" generation of the _1st_arguments:
So, I replaced most of the _1st_arguments with just 

    "${(@f)$(mix help | egrep "^mix " | tail -n+2 | sed 's/^mix //;s/\s\+#\s/:/')}"

The above line will allow the zsh user to autocomplete all available mix tasks. I just finished this and thought I should submit it for other oh-my-zsh users.
2015-11-09 18:13:44 +11:00

45 lines
1.1 KiB
Text

#compdef mix
#autoload
# Elixir mix zsh completion
local -a _1st_arguments
_1st_arguments=(
"${(@f)$(mix help | egrep "^mix " | tail -n+2 | sed 's/^mix //;s/\s\+#\s/:/')}"
'--help:Describe available tasks'
'--version:Prints the Elixir version information'
)
__task_list ()
{
local expl
declare -a tasks
tasks=(app.start archive archive.build archive.install archive.uninstall clean cmd compile compile.protocols deps deps.clean deps.compile deps.get deps.unlock deps.update do escript.build help hex hex.config hex.docs hex.info hex.key hex.outdated hex.owner hex.publish hex.search hex.user loadconfig local local.hex local.rebar new run test)
_wanted tasks expl 'help' compadd $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'
esac
;;
esac