Tab completion
About 436 words
unifi completion <shell> prints a completion script for bash, zsh, fish or PowerShell. With it, tab completes commands and flags, and also the things they name: contexts, sites, clients, devices, ports and themes come live from your configuration and controller.
$ unifi ports poe "Core Switch" Cam<tab>
Camera\ Backyard Camera\ Driveway Camera\ Front\ DoorIf you installed unifi-cli with Homebrew, the cask already installed the scripts for bash, zsh and fish and you can skip the rest of this page.
bash
Completion in bash needs the bash-completion package.
# this session
source <(unifi completion bash)
# every session, Linux
unifi completion bash | sudo tee /etc/bash_completion.d/unifi > /dev/null
# every session, macOS with Homebrew
unifi completion bash > "$(brew --prefix)/etc/bash_completion.d/unifi"zsh
zsh needs its completion system loaded, which means autoload -U compinit; compinit in ~/.zshrc.
# this session
source <(unifi completion zsh)
# every session
unifi completion zsh > "${fpath[1]}/_unifi"fish
# this session
unifi completion fish | source
# every session
unifi completion fish > ~/.config/fish/completions/unifi.fishPowerShell
# this session
unifi completion powershell | Out-String | Invoke-Expression
# every session
unifi completion powershell >> $PROFILEStart a new shell after installing a script for every session.
How live completion behaves
Completing a context or theme name reads local files and is instant. Completing a client, device, port, network or site name asks the controller, with the current context or the --context and --site already on the line. The candidates are cached for 60 seconds, so the second tab doesn't wait. When the controller can't be reached, completion offers nothing; it doesn't print an error into your command line.
In zsh, fish and PowerShell every candidate carries a description, which makes look-alike names easy to tell apart:
$ unifi ports set "Core Switch" <tab>
Home Assistant -- port 1 · up · 1 GbE
Proxmox Node 1 -- port 2 · up · 1 GbE
Printer -- port 4 · up · 100 FE
$ unifi clients get --network <tab>
Default -- VLAN 1
Trusted -- VLAN 10
IoT -- VLAN 20--filter completes too: first the field names of the command, then, once a field is typed, the operators with what they mean, and after a value && and ||.
$ unifi clients get --filter sig<tab>
signalDbm
$ unifi clients get --filter signalDbm<tab>
signalDbm == -- equals
signalDbm != -- does not equal
signalDbm contains -- contains
signalDbm startswith -- starts with
signalDbm < -- less thanNames with spaces are completed with the escaping your shell needs.
The release archives carry the same scripts in a completions/ directory, generated at release time, in case you'd rather install a file than run a command.
