# nmcli completion -*- shell-script -*- # Use of this file is deprecated. Upstream completion is available in # NetworkManager >= 0.9.8.0, use that instead. proc _nmcli_list { setglobal COMPREPLY = ''( $( compgen -W '$1' -- "$cur" ) ) } proc _nmcli_con_id { local IFS=$'\n' setglobal COMPREPLY = ''( $( compgen -W "$(nmcli con list 2>/dev/null | \ tail -n +2 | awk -F ' {2,}' '{print $1 }')" -- "$cur" ) ) } proc _nmcli_con_uuid { setglobal COMPREPLY = ''( $( compgen -W "$(nmcli con list 2>/dev/null | \ tail -n +2 | awk -F ' {2,}' '{print $2}')" -- "$cur" ) ) } proc _nmcli_ap_ssid { local IFS=$'\n' setglobal COMPREPLY = ''( $( compgen -W "$(nmcli dev wifi list 2>/dev/null | \ tail -n +2 | awk -F ' {2,}' '{print $1}')" -- "$cur" ) ) } proc _nmcli_ab_bssid { setglobal COMPREPLY = ''( $( compgen -W "$(nmcli dev wifi list 2>/dev/null | \ tail -n +2 | awk -F ' {2,}' '{print $2}')" -- "$cur" ) ) } proc _nmcli { local cur prev words cword _init_completion || return match $prev { with -m|--mode setglobal COMPREPLY = ''( $( compgen -W 'tabular multiline' -- "$cur" ) ) return 0 with -f|--fields setglobal COMPREPLY = ''( $( compgen -W 'all common' -- "$cur" ) ) return 0 with -e|--escape _nmcli_list "yes no" return 0 with id _nmcli_con_id return 0 with uuid _nmcli_con_uuid return 0 with iface _available_interfaces return 0 with bssid _nmcli_ab_bssid return 0 with wep-key-type _nmcli_list "key phrase" return 0 } if [[ $cword -eq 1 ]] { if [[ "$cur" == -* ]] { setglobal COMPREPLY = ''( $( compgen -W '--terse --pretty --mode --fields --escape --version --help' -- "$cur" ) ) } else { setglobal COMPREPLY = ''( $( compgen -W "nm con dev" -- "$cur" ) ) } } else { local object=$(words[1]) local command=$(words[2]) match $object { with nm match $command { with enable _nmcli_list "true false" return 0 with sleep _nmcli_list "true false" return 0 with wifi _nmcli_list "on off" return 0 with wwan _nmcli_list "on off" return 0 with wimax _nmcli_list "on off" return 0 } setglobal COMPREPLY = ''( $( compgen -W 'status permissions enable sleep wifi wwan wimax' -- "$cur" ) ) with con match $command { with list setglobal COMPREPLY = ''( $( compgen -W 'id uuid' -- "$cur" ) ) return 0 with up if [[ "$cur" == -* ]] { setglobal COMPREPLY = ''( $( compgen -W '--nowait --timeout' \ -- "$cur" ) ) } else { setglobal COMPREPLY = ''( $( compgen -W 'id uuid iface ap nsp' \ -- "$cur" ) ) } return 0 with down setglobal COMPREPLY = ''( $( compgen -W 'id uuid' -- "$cur" ) ) return 0 with delete setglobal COMPREPLY = ''( $( compgen -W 'id uuid' -- "$cur" ) ) return 0 } setglobal COMPREPLY = ''( $( compgen -W 'list status up down delete' \ -- "$cur" ) ) with dev match $command { with list setglobal COMPREPLY = ''( $( compgen -W 'iface' -- "$cur" ) ) return 0 with disconnect if [[ "$cur" == -* ]] { setglobal COMPREPLY = ''( $( compgen -W '--nowait --timeout' \ -- "$cur" ) ) } else { setglobal COMPREPLY = ''( $( compgen -W 'iface' -- "$cur" ) ) } return 0 with wifi local subcommand=$(words[3]) match $subcommand { with list setglobal COMPREPLY = ''( $( compgen -W 'iface bssid' \ -- "$cur" ) ) return 0 with connect if [[ "$cur" == -* ]] { setglobal COMPREPLY = ''( $( compgen -W '--private --nowait --timeout' -- "$cur" ) ) } else { if [[ "$prev" == "connect" ]] { _nmcli_ap_ssid } else { setglobal COMPREPLY = ''( $( compgen -W 'password wep-key-type iface bssid name' \ -- "$cur" ) ) } } return 0 } setglobal COMPREPLY = ''( $( compgen -W 'list connect' -- "$cur" ) ) return 0 } setglobal COMPREPLY = ''( $( compgen -W 'status list disconnect wifi' \ -- "$cur" ) ) } } return 0 } && complete -F _nmcli nmcli # ex: ts=4 sw=4 et filetype=sh