Skip to content

Tab-complete every spell

$ grim completion zsh

grim has many commands, and most of the long ones come in families: server:dev:add-project, infra:aws-cloudtrail. Nobody types those from memory twice. Set completion up once per machine, right after the install, and Tab does it.

Usage

$ grim completion zsh > ~/.grim/completion.zsh     # write the script once
$ echo 'source ~/.grim/completion.zsh' >> ~/.zshrc # load it in every shell
$ grim completion fish | source                    # fish, current session only

It runs from anywhere. With no argument the shell is taken from $SHELL. bash, zsh and fish are supported; bash additionally needs the bash-completion package.

Arguments and options

Dump the shell completion script

Usage

grim completion [--debug] [--] [<shell>]

Arguments

Argument Description
shell The shell type (e.g. "bash"), the value of the "$SHELL" env var will be used if this is not given (optional)

Options

Option Description
--debug Tail the completion debug log

What it actually does

  1. Prints a script to standard output. Nothing is installed and no file is touched. Where the script goes is up to you, which is why the examples redirect it.
  2. The script calls grim back. On every Tab your shell asks grim for the candidates, so the suggestions always match the version you have installed: new commands appear after grim self-update with no second setup.

Pitfalls

Nothing happens on Tab

The script was written but the running shell has not loaded it. Open a new terminal, or source the file by hand. After that, grim completion --debug follows the log of what the shell asked and what grim answered.

After it finishes

Open a new shell and try grim ser and Tab. Command names and option names complete.