Skip to content

Instantly share code, notes, and snippets.

@hamann
Created April 2, 2015 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hamann/39371c46806e14ab3853 to your computer and use it in GitHub Desktop.
Save hamann/39371c46806e14ab3853 to your computer and use it in GitHub Desktop.
_mix zsh completion
#compdef mix
#autoload
# Elixir mix zsh completion
local -a _1st_arguments
_1st_arguments=(
'archive:Archive this project into a .ez file'
'archive.build:Archive this project into a .ez file'
'archive.install:Install an archive locally'
'archive.uninstall:Uninstall archives'
'clean:Clean generated application files'
'compile:Compile source files'
'deps:List dependencies and their status'
"deps.clean:Remove dependencies' files"
'deps.compile:Compile dependencies'
'deps.get:Get all out of date dependencies'
'deps.unlock:Unlock the given dependencies'
'deps.update:Update dependencies'
'do:Executes the commands separated by comma'
'ecto.create:Create the storage for the repo'
'ecto.drop:Drop the storage for the repo'
'ecto.gen.migration:Generate a new migration for the repo'
'ecto.gen.repo:Generate a new repository'
'ecto.migrate:Run migrations up on a repo'
'ecto.rollback:Rollback migrations from a repo'
'escriptize:Generates an escript for the project'
'help:Print help information for tasks'
'hex:Print hex help information'
'hex.config:Read or update hex config'
'hex.docs:Publish docs for package'
'hex.info:Print hex information'
'hex.key:Hex API key tasks'
'hex.owner:Hex package ownership tasks'
'hex.publish:Publish a new package version'
'hex.search:Search for package names'
'hex.user:Hex user tasks'
'local:List local tasks'
'local.install:Install a task or an archive locally'
'local.rebar:Install rebar locally'
'local.uninstall:Uninstall local tasks or archives'
'local.hex:Install Hex locally'
'new:Creates a new Elixir project'
'phoenix.gen.resource:Generates resource files'
'phoenix.new:Create a new Phoenix application'
'phoenix.routes:Prints all routes'
'phoenix.server:Starts applications and their servers'
'release:Build a release for the current mix application.'
'release.clean:Clean up any release-related files.'
'release.plugins:View information about active release plugins'
'run:Run the given file or expression'
"test:Run a project's tests"
'--help:Describe available tasks'
'--version:Prints the Elixir version information'
)
__task_list ()
{
local expl
declare -a tasks
tasks=(archive clean compile deps deps.clean deps.compile deps.get deps.unlock deps.update do escriptize help local local.install local.rebar local.uninstall 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
@jasonm23
Copy link

jasonm23 commented Jul 20, 2016

I know this is a bit old, but it's probably better to dynamically build the 1st arguments array, using something like this:

IFS=$'\n' _1st_arguments=($(
                             mix --help             \
                               | tr -s ' '          \
                               | sed -e 's/ # /:/'  \
                                   -e 's/^mix //'   \
                                   -e 's/^mix:.*//' \
                                   -e 's/^iex.*//'  \
                               | sort -u
                           ))

_1st_arguments+=(
  '--help:Describe available tasks'
  '--version:Prints the Elixir version information'
)

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