From e118561a3762971c6cb00505e11cb9d00176f0c4 Mon Sep 17 00:00:00 2001 From: Shohei YOSHIDA Date: Tue, 24 Mar 2026 18:02:45 +0900 Subject: [PATCH] use dynamic completion but it seems we should use cache --- src/_mix | 172 +++++++++++++++++++++++-------------------------------- 1 file changed, 72 insertions(+), 100 deletions(-) diff --git a/src/_mix b/src/_mix index 4bdb5af..9ee8904 100644 --- a/src/_mix +++ b/src/_mix @@ -393,109 +393,81 @@ _mix() { } _mix_tasks() { - # mix help | \grep -vE 'phx\.|hex\.' | perl -wln -e 'm{^mix (\S+)\s+#\s+(.+)} and print qq("$1:$2")' - # mix compile --list | perl -wln -e 'm{^mix (\S+)\s+#\s+(.+)} and print qq("$1:$2")' - local -a mix_tasks=( - "app.config:Configures all registered apps" - "app.start:Starts all registered apps" - "app.tree:Prints the application tree" - "archive:Lists installed archives" - "archive.build:Archives this project into a .ez file" - "archive.install:Installs an archive locally" - "archive.uninstall:Uninstalls archives" - "clean:Deletes generated application files" - "cmd:Executes the given command" - "compile:Compiles source files" - "compile.app:Writes a '.app' file" - "compile.elixir:Compiles Elixir source files" - "compile.erlang:Compiles Erlang source files" - "compile.leex:Compiles Leex source files" - "compile.yecc:Compiles Yecc source files" - "deps:Lists dependencies and their status" - "deps.clean:Deletes the given dependencies' files" - "deps.compile:Compiles dependencies" - "deps.get:Fetches unavailable and out of date dependencies" - "deps.tree:Prints the dependency tree" - "deps.unlock:Unlocks the given dependencies" - "deps.update:Updates the given dependencies" - "do:Executes the tasks separated by plus" - "escript:Lists installed escripts" - "escript.build:Builds an escript for the project" - "escript.install:Installs an escript locally" - "escript.uninstall:Uninstalls escripts" - "eval:Evaluates the given code" - "format:Formats the given files/patterns" - "help:Prints help information for tasks, aliases, modules, and applications" - "loadconfig:Loads and persists the given configuration" - "local:Lists tasks installed locally via archives" - "local.rebar:Installs Rebar locally" - "new:Creates a new Elixir project" - "profile.cprof:Profiles the given file or expression with cprof" - "profile.eprof:Profiles the given file or expression with eprof" - "profile.fprof:Profiles the given file or expression with fprof" - "profile.tprof:Profiles the given file or expression with tprof" - "release:Assembles a self-contained release" - "release.init:Generates sample files for releases" - "run:Runs the current application" - "test:Runs a project's tests" - "test.coverage:Build report from exported test coverage" - "xref:Prints cross reference information" - ) + local -a mix_tasks=() + if (( $+commands[perl] )); then + mix_tasks=(${(f)"$(mix help | perl -lne 'm{^mix (\S+)\s+#\s+(.+)} and print qq($1:$2)')"}) + else + local -a builtin_tasks=( + "app.config:Configures all registered apps" + "app.start:Starts all registered apps" + "app.tree:Prints the application tree" + "archive:Lists installed archives" + "archive.build:Archives this project into a .ez file" + "archive.install:Installs an archive locally" + "archive.uninstall:Uninstalls archives" + "clean:Deletes generated application files" + "cmd:Executes the given command" + "compile:Compiles source files" + "compile.app:Writes a '.app' file" + "compile.elixir:Compiles Elixir source files" + "compile.erlang:Compiles Erlang source files" + "compile.leex:Compiles Leex source files" + "compile.yecc:Compiles Yecc source files" + "deps:Lists dependencies and their status" + "deps.clean:Deletes the given dependencies' files" + "deps.compile:Compiles dependencies" + "deps.get:Fetches unavailable and out of date dependencies" + "deps.tree:Prints the dependency tree" + "deps.unlock:Unlocks the given dependencies" + "deps.update:Updates the given dependencies" + "do:Executes the tasks separated by plus" + "escript:Lists installed escripts" + "escript.build:Builds an escript for the project" + "escript.install:Installs an escript locally" + "escript.uninstall:Uninstalls escripts" + "eval:Evaluates the given code" + "format:Formats the given files/patterns" + "help:Prints help information for tasks, aliases, modules, and applications" + "loadconfig:Loads and persists the given configuration" + "local:Lists tasks installed locally via archives" + "local.rebar:Installs Rebar locally" + "new:Creates a new Elixir project" + "profile.cprof:Profiles the given file or expression with cprof" + "profile.eprof:Profiles the given file or expression with eprof" + "profile.fprof:Profiles the given file or expression with fprof" + "profile.tprof:Profiles the given file or expression with tprof" + "release:Assembles a self-contained release" + "release.init:Generates sample files for releases" + "run:Runs the current application" + "test:Runs a project's tests" + "test.coverage:Build report from exported test coverage" + "xref:Prints cross reference information" + ) - # hex is a package manager - # mix help | perl -wln -e 'm{^mix (hex\.\S+)\s+#\s+(.+)} and print qq("$1:$2")' - local -a hex_tasks=( - "hex.audit:Shows retired Hex deps for the current project" - "hex.build:Builds a new package version locally" - "hex.config:Reads, updates or deletes local Hex config" - "hex.docs:Fetches or opens documentation of a package" - "hex.info:Prints Hex information" - "hex.organization:Manages Hex.pm organizations" - "hex.outdated:Shows outdated Hex deps for the current project" - "hex.owner:Manages Hex package ownership" - "hex.package:Fetches or diffs packages" - "hex.publish:Publishes a new package version" - "hex.registry:Manages local Hex registries" - "hex.repo:Manages Hex repositories" - "hex.retire:Retires a package version" - "hex.search:Open and perform searches" - "hex.sponsor:Show Hex packages accepting sponsorships" - "hex.user:Manages your Hex user account" - ) + # mix help | perl -wln -e 'm{^mix (hex\.\S+)\s+#\s+(.+)} and print qq("$1:$2")' + local -a hex_tasks=( + "hex.audit:Shows retired Hex deps for the current project" + "hex.build:Builds a new package version locally" + "hex.config:Reads, updates or deletes local Hex config" + "hex.docs:Fetches or opens documentation of a package" + "hex.info:Prints Hex information" + "hex.organization:Manages Hex.pm organizations" + "hex.outdated:Shows outdated Hex deps for the current project" + "hex.owner:Manages Hex package ownership" + "hex.package:Fetches or diffs packages" + "hex.publish:Publishes a new package version" + "hex.registry:Manages local Hex registries" + "hex.repo:Manages Hex repositories" + "hex.retire:Retires a package version" + "hex.search:Open and perform searches" + "hex.sponsor:Show Hex packages accepting sponsorships" + "hex.user:Manages your Hex user account" + ) - # mix help | perl -wln -e 'm{^mix (phx\.\S+)\s+#\s+(.+)} and print qq("$1:$2")' - local -a phoenix_tasks=( - "phx.digest:Digests and compresses static files" - "phx.digest.clean:Removes old versions of static assets." - "phx.gen:Lists all available Phoenix generators" - "phx.gen.auth:Generates authentication logic for a resource" - "phx.gen.cert:Generates a self-signed certificate for HTTPS testing" - "phx.gen.channel:Generates a Phoenix channel" - "phx.gen.context:Generates a context with functions around an Ecto schema" - "phx.gen.embedded:Generates an embedded Ecto schema file" - "phx.gen.html:Generates context and controller for an HTML resource" - "phx.gen.json:Generates context and controller for a JSON resource" - "phx.gen.live:Generates LiveView, templates, and context for a resource" - "phx.gen.notifier:Generates a notifier that delivers emails by default" - "phx.gen.presence:Generates a Presence tracker" - "phx.gen.release:Generates release files and optional Dockerfile for release-based deployments" - "phx.gen.schema:Generates an Ecto schema and migration file" - "phx.gen.secret:Generates a secret" - "phx.gen.socket:Generates a Phoenix socket handler" - "phx.new:Creates a new Phoenix v1.8.5 application" - "phx.new.ecto:Creates a new Ecto project within an umbrella project" - "phx.new.web:Creates a new Phoenix web project within an umbrella project" - "phx.routes:Prints all routes" - "phx.server:Starts applications and their servers" - ) + mix_tasks=($builtin_tasks[@] $hex_tasks[@]) + fi - local -a tasks=( - $mix_tasks[@] - $hex_tasks[@] - $phoenix_tasks[@] - ) - - _describe -t tasks 'task' tasks + _describe -t tasks 'task' mix_tasks } _mix_profile_tasks() {