Articles

Tab completion for jailops

Shell completion for the jailops command on FreeBSD: what Tab completes (commands, flags, and the names of jails, images, networks, projects and firewall policies from the server), how to install it for bash, zsh and fish, and how to turn it on.

What it completes

More than command names.

Commands and flags complete on their own, offline. The names come from the server you are connected to, so Tab offers what exists:

  • Jails: jailops start, stop, shell, exec, info, config and every other command that takes a jail.
  • Configuration keys: after the jail in jailops config set JAIL, the keys of that jail (boot.autostart, limits.memory and so on), and after firewall.policies the names of the firewall policies, also in a comma separated list.
  • Flags that name something: --image, --network, --storage, --profile, --depends and --firewall-policy offer the images, networks, storage grants, profiles, jails and firewall policies of the project.
  • Access: in jailops app allow APP --from it completes the app and the source: the kinds jail:, set: and host, then the jails or the address sets of the project.
  • References: wherever a firewall rule, an address set, firewall test or app allow takes one (--from, --to, --address), Tab offers the kinds jail:, set:, tag: and any, and after a kind the names that exist in the project. Rules have their own words too: jailops firewall rule add web in --action offers allow and deny, and rule remove web lists the rules of the policy with their comments.
  • Projects, backups and operations by name.

When no server answers, the shell gets no names and no error. Nothing is slow and nothing breaks: you type the name yourself.

Bash on FreeBSD

Two packages and one line.

The client package installs the completion script where bash-completion looks for it, /usr/local/share/bash-completion/completions/jailops. Bash itself does not load it until the bash-completion package is installed and its script is sourced from your .bashrc. FreeBSD's default shell is not bash, so install it and, if you want it for your login, make it your shell:

once, as root
# pkg install bash bash-completion
# chsh -s /usr/local/bin/bash youruser

Then add the line that the bash-completion package prints to the .bashrc of that user:

~/.bashrc
[[ $PS1 && -f /usr/local/share/bash-completion/bash_completion.sh ]] && \
    source /usr/local/share/bash-completion/bash_completion.sh

Open a new shell and try it: jailops st and Tab. If a jail name does not complete, the shell is not connected to a server (check with jailops list), not a problem with completion.

zsh and fish

Little to do.

  • zsh: the package installs /usr/local/share/zsh/site-functions/_jailops. It works once compinit is on: autoload -U compinit && compinit in ~/.zshrc.
  • fish: finds it by itself, from /usr/local/share/fish/vendor_completions.d/.

A binary installed by hand

The command prints the script.

Without the package, for example a binary from the release archives or from just build-freebsd, the command prints the script for each shell:

without the package
$ source <(jailops completion bash)
$ jailops completion zsh > "${fpath[1]}/_jailops"
$ jailops completion fish > ~/.config/fish/completions/jailops.fish

For bash you can also save the output as /usr/local/share/bash-completion/completions/jailops instead of sourcing it in every shell.

Other hosts

It follows the remote you are on.

The names are asked of the server the command would talk to: the local socket on the host, or the remote you chose on a workstation. With a client on your laptop that talks to a host, jailops start and Tab lists the jails of that host's project, which is the quickest way to see what is there before you type anything. jailops-sync has its completion too.

More articles

Try it on one server.

Try the console from the screenshots, install on a clean FreeBSD 15.1 machine, or add JailOps to a host you already run.