|
| 1 | +--- |
| 2 | +title: CLI plugins |
| 3 | +weight: 2 |
| 4 | +--- |
| 5 | + |
| 6 | + | ⚡ Requirement | Lima >= 2.0 | |
| 7 | + |----------------|-------------| |
| 8 | + |
| 9 | +Lima supports a plugin-like command aliasing system similar to `git`, `kubectl`, and `docker`. When you run a `limactl` command that doesn't exist, Lima will automatically look for an external program named `limactl-<command>` in your system's PATH. |
| 10 | + |
| 11 | +## Creating Custom Aliases |
| 12 | + |
| 13 | +To create a custom alias, create an executable script with the name `limactl-<alias>` and place it somewhere in your PATH. |
| 14 | + |
| 15 | +**Example: Creating a `ps` alias for listing instances** |
| 16 | + |
| 17 | +1. Create a script called `limactl-ps`: |
| 18 | + ```bash |
| 19 | + #!/bin/sh |
| 20 | + # Show instances in a compact format |
| 21 | + limactl list --format table "$@" |
| 22 | + ``` |
| 23 | + |
| 24 | +2. Make it executable and place it in your PATH: |
| 25 | + ```bash |
| 26 | + chmod +x limactl-ps |
| 27 | + sudo mv limactl-ps /usr/local/bin/ |
| 28 | + ``` |
| 29 | + |
| 30 | +3. Now you can use it: |
| 31 | + ```bash |
| 32 | + limactl ps # Shows instances in table format |
| 33 | + limactl ps --quiet # Shows only instance names |
| 34 | + ``` |
| 35 | + |
| 36 | +**Example: Creating an `sh` alias** |
| 37 | + |
| 38 | +```bash |
| 39 | +#!/bin/sh |
| 40 | +# limactl-sh - Connect to an instance shell |
| 41 | +limactl shell "$@" |
| 42 | +``` |
| 43 | + |
| 44 | +After creating this alias: |
| 45 | +```bash |
| 46 | +limactl sh default # Equivalent to: limactl shell default |
| 47 | +limactl sh myinstance bash # Equivalent to: limactl shell myinstance bash |
| 48 | +``` |
| 49 | + |
| 50 | +## How It Works |
| 51 | + |
| 52 | +1. When you run `limactl <unknown-command>`, Lima first tries to find a built-in command |
| 53 | +2. If no built-in command is found, Lima searches for `limactl-<unknown-command>` in your PATH |
| 54 | +3. If found, Lima executes the external program and passes all remaining arguments to it |
| 55 | +4. If not found, Lima shows the standard "unknown command" error |
| 56 | + |
| 57 | +This system allows you to: |
| 58 | +- Create personal shortcuts and aliases |
| 59 | +- Extend Lima's functionality without modifying the core application |
| 60 | +- Share custom commands with your team by distributing scripts |
0 commit comments