Zsh completion for custom script
I wrote a small script that starts the entire rsync system from https://wiki.archlinux.org/index.php/full_system_backup_with_rsync that takes multiple command line parameters and the hostname system as arguments. I would like to point out this type of autocomplete for things like ssh. However, I don't want to enter a user, as root is the only user who can do this.
Ideally I would like to type wholesystem.sh fi and populate the server.domain.com file
Here's my custom completion file. The options work, but the host is clearly not populating and I'm just lost where to go from here.
#compdef wholesystem.sh
typeset -A opt_args
_arguments \
'-h[help]' \
'-s[silent]' \
'-v[verbose]' \
'-d[dry run]' \
':remote system:_user_at_host:'
I could either get it from ~ / .ssh / known_hosts, which I'm fine with, or ... The backup system keeps backups in ~ / WholeSystems / host.domain.com / and I don't mind if it got its ideas from there.
source to share
I suggest something like this:
#compdef wholesystem.sh
_wholesystem.sh() {
typeset -A opt_args
_arguments \
'-h[help]' \
'-s[silent]' \
'-v[verbose]' \
'-d[dry run]' \
':remote system:_wholesystem_hosts'
}
_wholesystem_hosts() {
[...]
}
_wholesystem.sh
The content _wholesystem_hosts
depends on which host you want. For example, if you want the same hosts as ssh
, you can copy the code _ssh_hosts
from .../functions/Completion/Unix/_ssh
.
I don't know if this is appropriate, but it works.
source to share