Shell Completion
Shell command line completions are provided for bash, fish, and zsh.
The completion scripts are built into resticprofile and printed by the generate command, so they always match the version you have installed.
Bash
To load the completions in the current shell:
To install them permanently:
Fish
To load the completions in the current shell:
To install them permanently:
Zsh
The zsh completion proposes resticprofile commands and flags, and the profile and group names found in your configuration file. A description is shown next to each match:
It also completes restic commands and flags when the restic completion is installed.
Requirements
The zsh completion system (compinit) must be enabled. Frameworks like Oh My Zsh enable it for you. If you don’t use one, make sure your ~/.zshrc contains:
Try it in the current shell
The completions are available until you close the shell. To keep this method, add the line to your ~/.zshrc, after compinit.
Install permanently
zsh loads its completions from the directories listed in $fpath. Save the script in one of these directories, in a file named _resticprofile. The leading underscore is required: zsh ignores a file named resticprofile. The file doesn’t need to be executable.
Homebrew installs the bash, fish and zsh completions along with resticprofile. There’s nothing else to do, as long as Homebrew completions are enabled in your shell.
Oh My Zsh adds the completions directory of its custom folder to $fpath, and runs compinit itself:
There’s nothing to add to your ~/.zshrc.
Then add the directory to $fpath in your ~/.zshrc, before compinit:
/usr/local/share/zsh/site-functions is in the default $fpath on most systems (check with print -l $fpath):
There’s nothing to add to your ~/.zshrc.
Start a new shell (or run exec zsh) to load the completions.
Completing restic commands
resticprofile hands the completion of restic commands and flags (like backup or --host) over to the zsh completion provided by restic. Without it, only the resticprofile commands, flags and profile names are completed.
Packages of restic usually install it. If it’s missing, save it next to the resticprofile one, in a file named _restic:
Troubleshooting
If pressing TAB proposes file names instead of resticprofile commands, check that zsh knows about the completion:
This should print _resticprofile. If it prints nothing:
- the file must be named
_resticprofile, with the leading underscore - its directory must be listed in
$fpath(check withprint -l $fpath), and added beforecompinitruns - when using
sourceinstead, the line must come aftercompinit: zsh reportscommand not found: compdefotherwise - zsh caches the list of completions: delete the cache with
rm -f ~/.zcompdump*and start a new shell