Mage supports tab completion for all of its built-in flags as well as your
project’s targets. Pressing Tab after typing mage will suggest available
targets in the current directory, so you never have to remember exact names.
The easiest way to get tab completion is the built-in installer. Run
mage -install with the name of your shell:
mage -install bash
mage -install zsh
mage -install fish
mage -install powershell # also accepts "pwsh"
The installer will:
~/.config/mage/ (or the appropriate
platform-specific config directory)..bashrc, .zshrc,
PowerShell $PROFILE, etc.) so completions load automatically in every new
session.If mage can’t update your shell config file for any reason, it will print the line you need to add manually — so the command is always safe to run.
Running mage -install again for the same shell is safe. It replaces the
previous completion block rather than duplicating it.
Bash — the installer sources the completion script from your .bashrc
(preferred) or .bash_profile. It uses the standard complete built-in, so no
extra packages are required.
Zsh — the installer sources the script from your .zshrc (honoring
$ZDOTDIR if set). If compdef is not yet available when the script loads, it
automatically calls compinit first.
Fish — completions are placed in
$XDG_CONFIG_HOME/fish/completions/mage.fish (defaulting to
~/.config/fish/completions/). Fish loads files from this directory
automatically, so no startup-file modification is needed.
PowerShell — the installer writes a .ps1 script and sources it from your
$PROFILE. Both PowerShell Core (pwsh) and Windows PowerShell are supported.
If the profile file or its parent directory doesn’t exist yet, mage creates
them.
Under the hood, all of the completion scripts call:
mage -autocomplete
This prints a plain list of targets (one per line) for the current directory and exits. You can run it yourself to see what completions would be offered:
$ mage -autocomplete
build
clean
deploy
test
If you use a shell that isn’t directly supported, or you want to integrate mage
completions into a custom tool, you can wire up mage -autocomplete yourself.
The contract is simple:
cds to the project directory (or runs mage there) before
invoking it.For example, a minimal POSIX-shell completion function might look like:
_mage_complete() {
COMPREPLY=( $(mage -autocomplete 2>/dev/null) )
}
complete -F _mage_complete mage
Adapt this pattern for any environment that can execute a command and consume its line-delimited output.