NetworkManager/cli/completion/nmcli

347 lines
11 KiB
Text
Raw Normal View History

# nmcli(1) completion -*- shell-script -*-
# Originally based on
# https://github.com/GArik/bash-completion/blob/master/completions/nmcli
_nmcli_list()
{
COMPREPLY=( $( compgen -W '$1' -- $cur ) )
}
_nmcli_list_nl()
{
local IFS=$'\n'
COMPREPLY=( $( compgen -W '$1' -- $cur ) )
}
_nmcli_con_id()
{
echo "$(nmcli -t -f NAME con show c 2>/dev/null)"
}
_nmcli_con_uuid()
{
echo "$(nmcli -t -f UUID con show c 2>/dev/null)"
}
_nmcli_con_path()
{
echo "$(nmcli -t -f DBUS-PATH con show c 2>/dev/null)"
}
_nmcli_con_apath()
{
echo "$(nmcli -t -f DBUS-PATH con show a 2>/dev/null)"
}
_nmcli_ap_ssid()
{
echo "$(nmcli -t -f SSID dev wifi list 2>/dev/null)"
# without quotes
#ssids="$(nmcli -t -f SSID dev wifi list 2>/dev/null)"
#local IFS=$'\n'
#for ssid in $ssids; do
# temp="${ssid%\'}"
# temp="${temp#\'}"
# echo "$temp"
#done
}
_nmcli_ap_bssid()
{
echo "$(nmcli -e no -t -f BSSID dev wifi list 2>/dev/null)"
}
_nmcli_NM_devices()
{
echo "$(nmcli -t -f DEVICE dev status 2>/dev/null)"
}
_nmcli_NM_dev_MAC()
{
echo "$(nmcli -t dev show | grep HWADDR | cut -d':' -f2- | sort | uniq)"
}
_nmcli()
{
local cur prev words cword
_init_completion || return
case $prev in
-m|--mode)
_nmcli_list "tabular multiline"
return 0
;;
-f|--fields)
_nmcli_list "all common"
return 0
;;
-e|--escape)
_nmcli_list "yes no"
return 0
;;
id)
_nmcli_list_nl "$(_nmcli_con_id)"
return 0
;;
uuid)
_nmcli_list_nl "$(_nmcli_con_uuid)"
return 0
;;
path)
_nmcli_list_nl "$(_nmcli_con_path)"
return 0
;;
apath)
_nmcli_list_nl "$(_nmcli_con_apath)"
return 0
;;
iface | ifname)
#_available_interfaces
_nmcli_list_nl "$(_nmcli_NM_devices)"
return 0
;;
bssid)
_nmcli_list_nl "$(_nmcli_ap_bssid)"
return 0
;;
wep-key-type)
_nmcli_list "key phrase"
return 0
;;
autoconnect | stp | hairpin | private)
_nmcli_list "yes no"
return 0
;;
# connection types
type)
_nmcli_list "ethernet wifi wimax gsm cdma infiniband adsl bluetooth vpn \
olpc-mesh vlan bond bridge bond-slave bridge-slave"
return 0
;;
# VPN types
vpn-type)
_nmcli_list "vpn-type vpnc openvpn pptp openconnect openswan"
return 0
;;
# Bluetooth modes
bt-type)
_nmcli_list "panu dun-gsm dun-cdma"
return 0
;;
# InfiniBand transport modes
transport-mode)
_nmcli_list "datagram connected"
return 0
;;
# bonding modes
mode)
_nmcli_list "balance-rr active-backup balance-xor broadcast \
802.3ad balance-tlb balance-alb"
return 0
;;
# MAC addresses
mac)
_mac_addresses
return 0
;;
# master interface
master)
UUIDS=$(_nmcli_con_uuid)
DEVICES=$(_nmcli_NM_devices)
_nmcli_list "$DEVICES $UUIDS"
return 0
;;
esac
if [[ $cword -eq 1 ]] ; then
if [[ "$cur" == -* ]]; then
if [[ "$cur" == -[tpmfenavh] ]]; then
_nmcli_list "-t -p -m -f -e -n -a -v -h"
else
_nmcli_list "--terse --pretty --mode --fields --escape --nocheck --ask --version --help"
fi
else
_nmcli_list "general networking radio connection device"
fi
else
local object=${words[1]}
local command=${words[2]}
[[ $command == help ]] && return 0
case $object in
g|ge|gen|gene|gener|genera|general)
if [[ ${#words[@]} -gt 3 ]]; then
case $command in
s|st|sta|stat|statu|status | p|pe|per|perm|permi|permis|permiss|permissi|permissio|permission|permissions)
return 0
;;
l|lo|log|logg|loggi|loggin|logging)
_nmcli_list "level domains"
return 0
;;
esac
fi
_nmcli_list "status permissions logging help"
;;
n|ne|net|netw|netwo|networ|network|networki|networkin|networking)
if [[ ${#words[@]} -gt 3 ]]; then
case $command in
on | off)
return 0
;;
esac
fi
_nmcli_list "on off help"
;;
r|ra|rad|radi|radio)
if [[ ${#words[@]} -gt 3 ]]; then
case $command in
a|al|all | w|wi|wif|wifi | ww|wwa|wwan | wim|wima|wimax)
_nmcli_list "on off"
return 0
;;
esac
fi
_nmcli_list "all wifi wwan wimax help"
;;
c|co|con|conn|conne|connec|connect|connecti|connectio|connection)
if [[ ${#words[@]} -gt 3 ]]; then
case $command in
s|sh|sho|show)
local subcommand=${words[3]}
if [[ ${#words[@]} -gt 4 ]]; then
case $subcommand in
c|co|con|conf|confi|config|configu|configur|configure|configured)
_nmcli_list "id uuid path"
return 0
;;
a|ac|act|acti|activ|active)
_nmcli_list "id uuid path apath"
return 0
;;
esac
fi
_nmcli_list "configured active"
return 0
;;
u|up)
if [[ "$cur" == -* ]]; then
_nmcli_list "--nowait --timeout"
else
_nmcli_list "id uuid path iface ap nsp"
fi
return 0
;;
d|do|dow|down)
_nmcli_list "id uuid path apath"
return 0
;;
a|ad|add)
_nmcli_list "type con-name autoconnect ifname help"
return 0
;;
e|ed|edi|edit)
_nmcli_list "id uuid path type con-name"
return 0
;;
m|mo|mod|modi|modif|modify)
_nmcli_list_nl "$(_nmcli_con_id)"
return 0
;;
de|del|dele|delet|delete)
_nmcli_list "id uuid path"
return 0
;;
esac
fi
_nmcli_list "show up down add modify edit delete reload help"
;;
d|de|dev|devi|devic|device)
if [[ ${#words[@]} -gt 3 ]]; then
case $command in
sh|sho|show)
_nmcli_list_nl "$(_nmcli_NM_devices)"
return 0
;;
d|di|dis|disc|disco|discon|disconn|disconne|disconnec|disconnect)
if [[ "$cur" == -* ]]; then
_nmcli_list "--nowait --timeout"
else
_nmcli_list_nl "$(_nmcli_NM_devices)"
fi
return 0
;;
w|wi|wif|wifi)
local subcommand=${words[3]}
case $subcommand in
l|li|lis|list)
_nmcli_list "iface bssid"
return 0
;;
c|co|con|conn|conne|connec|connect)
if [[ "$cur" == -* ]]; then
_nmcli_list "--private --nowait --timeout"
else
if [[ "$prev" == "connect" ]]; then
_nmcli_list_nl "$(_nmcli_ap_ssid)"
else
_nmcli_list "password wep-key-type iface bssid name"
fi
fi
return 0
;;
r|re|res|resc|resca|rescan)
if [[ "$cur" == i* ]]; then
_nmcli_list "iface"
else
_nmcli_list_nl "$(_nmcli_NM_devices)"
fi
return 0
;;
esac
_nmcli_list "list connect scan"
return 0
;;
wim|wima|wimax)
local subcommand=${words[3]}
if [[ ${#words[@]} -gt 4 ]]; then
case $subcommand in
l|li|lis|list)
_nmcli_list "iface nsp"
return 0
;;
esac
fi
_nmcli_list "list"
return 0
;;
esac
fi
_nmcli_list "status show disconnect wifi wimax help"
;;
esac
fi
return 0
} &&
complete -F _nmcli nmcli
# ex: ts=4 sw=4 et filetype=sh