# 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 { setvar COMPREPLY = ''( $( compgen -W '$1' -- "$cur" ) ) } proc _nmcli_con_id { local IFS=$'\n' setvar COMPREPLY = ''( $( compgen -W "$(nmcli con list 2>/dev/null | \ tail -n +2 | awk -F ' {2,}' '{print $1 }')" -- "$cur" ) ) } proc _nmcli_con_uuid { setvar 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' setvar COMPREPLY = ''( $( compgen -W "$(nmcli dev wifi list 2>/dev/null | \ tail -n +2 | awk -F ' {2,}' '{print $1}')" -- "$cur" ) ) } proc _nmcli_ab_bssid { setvar 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 case (prev) { -m|--mode { setvar COMPREPLY = ''( $( compgen -W 'tabular multiline' -- "$cur" ) ) return 0 } -f|--fields { setvar COMPREPLY = ''( $( compgen -W 'all common' -- "$cur" ) ) return 0 } -e|--escape { _nmcli_list "yes no" return 0 } id { _nmcli_con_id return 0 } uuid { _nmcli_con_uuid return 0 } iface { _available_interfaces return 0 } bssid { _nmcli_ab_bssid return 0 } wep-key-type { _nmcli_list "key phrase" return 0 } } if [[ $cword -eq 1 ]] { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--terse --pretty --mode --fields --escape --version --help' -- "$cur" ) ) } else { setvar COMPREPLY = ''( $( compgen -W "nm con dev" -- "$cur" ) ) } } else { local object=${words[1]} local command=${words[2]} case (object) { nm { case (command) { enable { _nmcli_list "true false" return 0 } sleep { _nmcli_list "true false" return 0 } wifi { _nmcli_list "on off" return 0 } wwan { _nmcli_list "on off" return 0 } wimax { _nmcli_list "on off" return 0 } } setvar COMPREPLY = ''( $( compgen -W 'status permissions enable sleep wifi wwan wimax' -- "$cur" ) ) } con { case (command) { list { setvar COMPREPLY = ''( $( compgen -W 'id uuid' -- "$cur" ) ) return 0 } up { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--nowait --timeout' \ -- "$cur" ) ) } else { setvar COMPREPLY = ''( $( compgen -W 'id uuid iface ap nsp' \ -- "$cur" ) ) } return 0 } down { setvar COMPREPLY = ''( $( compgen -W 'id uuid' -- "$cur" ) ) return 0 } delete { setvar COMPREPLY = ''( $( compgen -W 'id uuid' -- "$cur" ) ) return 0 } } setvar COMPREPLY = ''( $( compgen -W 'list status up down delete' \ -- "$cur" ) ) } dev { case (command) { list { setvar COMPREPLY = ''( $( compgen -W 'iface' -- "$cur" ) ) return 0 } disconnect { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--nowait --timeout' \ -- "$cur" ) ) } else { setvar COMPREPLY = ''( $( compgen -W 'iface' -- "$cur" ) ) } return 0 } wifi { local subcommand=${words[3]} case (subcommand) { list { setvar COMPREPLY = ''( $( compgen -W 'iface bssid' \ -- "$cur" ) ) return 0 } connect { if [[ "$cur" == -* ]] { setvar COMPREPLY = ''( $( compgen -W '--private --nowait --timeout' -- "$cur" ) ) } else { if [[ "$prev" == "connect" ]] { _nmcli_ap_ssid } else { setvar COMPREPLY = ''( $( compgen -W 'password wep-key-type iface bssid name' \ -- "$cur" ) ) } } return 0 } } setvar COMPREPLY = ''( $( compgen -W 'list connect' -- "$cur" ) ) return 0 } } setvar COMPREPLY = ''( $( compgen -W 'status list disconnect wifi' \ -- "$cur" ) ) } } } return 0 } && complete -F _nmcli nmcli # ex: ts=4 sw=4 et filetype=sh