2021-06-16 22:35:12 +03:00
#compdef networkctl
2020-11-09 07:23:58 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2016-04-19 00:27:42 +03:00
2018-12-24 14:15:38 +03:00
(( $+functions[_networkctl_commands] )) ||
2019-04-05 12:39:14 +03:00
_networkctl_commands() {
local -a _networkctl_cmds
_networkctl_cmds=(
2016-04-19 00:27:42 +03:00
'list:List existing links'
2020-08-26 17:03:35 +03:00
'status:Show information about the specified links'
'lldp:Show Link Layer Discovery Protocol status'
'label:Show address labels'
'delete:Delete virtual netdevs'
'up:Bring devices up'
'down:Bring devices down'
'renew:Renew dynamic configurations'
'forcerenew:Trigger DHCP reconfiguration of all connected clients'
'reconfigure:Reconfigure interfaces'
'reload:Reload .network and .netdev files'
2019-04-05 12:39:14 +03:00
)
if (( CURRENT == 1 )); then
_describe -t commands 'networkctl command' _networkctl_cmds
else
local curcontext="$curcontext"
local -a _links
cmd="${${_networkctl_cmds[(r)$words[1]:*]%%:*}}"
2020-08-26 17:03:35 +03:00
case $cmd in
2020-08-27 11:01:36 +03:00
(list|status|up|down|lldp|delete|renew|forcerenew|reconfigure)
2020-08-26 17:03:35 +03:00
_links=( "${(foa)$(networkctl list --no-legend | awk 'BEGIN{OFS=":"} {sub(/[[ \t]+/, ""); print $2,$0}' 2>/dev/null)}" )
if [[ -n "$_links" ]]; then
_describe -t links 'links' _links
else
_message "no links"
fi
;;
*)
_message "no more options"
;;
esac
2016-04-19 00:27:42 +03:00
fi
2019-04-05 12:39:14 +03:00
}
2016-04-19 00:27:42 +03:00
2021-05-12 18:22:14 +03:00
(( $+functions[_networkctl_get_json] )) || _networkctl_get_json()
{
local -a _json_forms
_json_forms=( $(networkctl --json=help 2>/dev/null) )
_values 'format' $_json_forms
}
2016-04-19 00:27:42 +03:00
_arguments \
{-a,--all}'[Show all links with status]' \
'--no-pager[Do not pipe output into a pager]' \
'--no-legend[Do not print the column headers]' \
{-h,--help}'[Show this help]' \
'--version[Show package version]' \
2021-05-12 18:22:14 +03:00
'--json[Shows output formatted as JSON]:format:_networkctl_get_json' \
2018-12-24 14:15:38 +03:00
'*::networkctl commands:_networkctl_commands'