Hop CLI Completions
Hop CLI supports tab completion for bash, zsh and fish
To enable tab completion, run the following command:
hop completions <shell> > /some/path/to/hop-completion
where <shell>
is one of bash
, zsh
or fish
.
If you get permission denied error, you can try running the following command:
# pipe output to sudo tee and do not output to the tty
$ hop completions <shell> | sudo tee /some/path/to/hop-completion > /dev/null
The commands above will output the completion script to the specified path. Which will look something like this:
$ hop completions zsh
#compdef hop
autoload -U is-at-least
_hop() {
typeset -A opt_args
typeset -a _arguments_options
local ret=1
...
_hop "$@"
The correct method of installing a completion script can depend on both your shell and your configuration.
Installation
Completions typically will be installed automatically by your shell’s package manager and the script will try to install them.
Zsh
This example shows how to enable tab completion for zsh, it assumes you are
using oh-my-zsh
.
$ hop completions zsh > ~/.oh-my-zsh/completions/_hop
Your completion script must have the name in the format of _ followed by the name of the application.
Without oh-my-zsh
, you will need to add a path for completion scripts to your
function path, and turn on completion script autoloading. First, add these lines
to ~/.zshrc
:
fpath=(~/.zsh/completion $fpath)
autoload -U compinit
compinit
Next, create a directory at ~/.zsh/completion
and copy the completion script
to the new directory.
Bash
If you have bash-completion
installed, you can just copy your new completion script to the
/usr/local/etc/bash_completion.d
or /usr/share/bash-completion/completions
directory using the following command:
$ hop completions bash > /usr/local/etc/bash_completion.d/hop
Without bash-completion, you will need to source the completion script directly.
Copy it to a directory such as ~/.bash_completions/
, and then add the
following line to ~/.bash_profile
or ~/.bashrc
:
$ source ~/.bash_completions/hop
Fish
To enable tab completion for fish, copy the completion script to the
~/.config/fish/completions
or /usr/share/fish/completions
directory using
the following command:
$ hop completions fish > ~/.config/fish/completions/hop.fish