Shell Completions

macpine provides shell completion scripts for Bash, Zsh, Fish, and PowerShell to help you work faster by autocompleting commands, instance names, and flags.

Generating Completion Scripts

You can generate the completion script for your shell of choice using the alpine completion command.

# Show help for the completion command
alpine completion --help

# Generate the script for Bash
alpine completion bash

# Generate the script for Zsh
alpine completion zsh

Installation Instructions

After generating the script, you need to install it in the correct location for your shell.

Bash

For Bash, you typically need to have bash-completion installed (e.g., via brew install bash-completion).

# macOS with Homebrew
alpine completion bash > "$(brew --prefix)/etc/bash_completion.d/alpine"

You may need to restart your shell or source your .bash_profile for the changes to take effect.

Zsh

For Zsh, you can place the completion file in a directory that is part of your $fpath.

  1. Create a directory for completions if you don't have one:

    mkdir -p ~/.zsh/completions

  2. Add this directory to your $fpath in your .zshrc file. Make sure it's added before compinit is called.

    # Add this to ~/.zshrc
    fpath=($HOME/.zsh/completions $fpath)
    
    # ... (rest of your .zshrc)
    autoload -Uz compinit && compinit

  3. Generate the completion script. Note the filename must be _alpine.

    alpine completion zsh > ~/.zsh/completions/_alpine

  4. Restart your shell.

Fish

For Fish, place the completion script in the completions directory.

alpine completion fish > ~/.config/fish/completions/alpine.fish

PowerShell

For PowerShell, add the output to your PowerShell profile.

alpine completion powershell >> $PROFILE

Usage Examples

Once installed, you can use the Tab key to autocomplete:

# Tab-complete commands
$ alpine l<TAB>
launch  list

# Tab-complete instance names
$ alpine ssh <TAB>
flat-fight      ignorant-punch

# Tab-complete flags
$ alpine launch --<TAB>
--arch    --cpu     --disk    --help    --image   --memory  --mount   --name    --port    --shared  --ssh