# gnokii(1) completion -*- shell-script -*- proc _gnokii_memory_type { # TODO: reduce the number of choices setglobal COMPREPLY = '( '$( compgen -W "IN OU SM ME MT" -- "$cur" ) ) } proc _gnokii { var cur = '', prev = '', words = '', cword = '', pprev = '', tprev = '', fprev = '' _init_completion || return match $prev { with --config _filedir return with --phone var config_file = '' for config_file in ["$XDG_CONFIG_HOME/gnokii/config" \ "$HOME/.config/gnokii/config" "$HOME/.gnokiirc" \ "$XDG_CONFIG_DIRS/gnokii/config" /etc/gnokiirc] { [[ -f $config_file ]] && break } [[ ! -f $config_file ]] && return setglobal COMPREPLY = '( '$( compgen -W \ "$( sed -n 's/^\[phone_\(.*\)\]/\1/p' $config_file )" \ -- "$cur" ) ) return with --help setglobal COMPREPLY = '( '$( compgen -W 'all monitor sms mms phonebook calendar todo dial profile settings wap logo ringtone security file other' -- "$cur" ) ) return with --version|--shell|ping return # MONITOR with --monitor setglobal COMPREPLY = '( '$( compgen -W 'delay once' -- "$cur" ) ) return with --getdisplaystatus|--displayoutput return with --netmonitor setglobal COMPREPLY = '( '$( compgen -W 'reset off field devel next nr' \ -- "$cur" ) ) return # SMS with --sendsms # (how)TODO ? return with --savesms setglobal COMPREPLY = '( '$( compgen -W '--sender --smsc --smscno --folder --location --sent --read --deliver --datetime' -- "$cur" ) ) return with --memory-type|--memory|--getsms|--deletesms|--getmms|--deletemms|\ --getphonebook|--deletephonebook _gnokii_memory_type return with --getsmsc|--getcalendarnote|--deletecalendarnote|--gettodo|\ --getspeeddial # TODO: grab a specific entry ID return with --setsmsc|--smsreader|--createsmsfolder|--deletealltodos|\ --showsmsfolderstatus return with --deletesmsfolder|--folder # TODO: folderid return with --writephonebook setglobal COMPREPLY = '( '$( compgen -W '--overwrite --find-free --memory-type --location --vcard --ldif' -- "$cur" ) ) return with --writecalendarnote|--writetodo _filedir vcf return # DIAL with --setspeeddial|--dialvoice|--senddtmf|--answercall|--hangup # TODO return with --divert setglobal COMPREPLY = '( '$( compgen -W '--op' -- "$cur" ) ) return # PROFILE with --getprofile|--setactiveprofile # TODO return with --setprofile|--getactiveprofile return # SETTINGS with --reset setglobal COMPREPLY = '( '$( compgen -W 'soft hard' -- "$cur" ) ) return with --setdatetime|--setalarm # TODO return with --getdatetime|--getalarm return # WAP with --getwapbookmark|--writewapbookmark|--deletewapbookmark|\ --getwapsetting|--writewapsetting|--activatewapsetting return # LOGOS with --sendlogo setglobal COMPREPLY = '( '$( compgen -W 'caller op picture' -- "$cur" ) ) return with --setlogo|--getlogo setglobal COMPREPLY = '( '$( compgen -W 'op startup caller dealer text' \ -- "$cur" ) ) return with --viewlogo # TODO: logofile return with --entersecuritycode setglobal COMPREPLY = '( '$( compgen -W 'PIN PIN2 PUK PUK2 SEC' -- "$cur" ) ) return # TODO: RINGTONES } # second level completion if [[ $((cword-2)) -ge 1 && ${words[cword-2]} =~ --* ]] { set pprev = $(words[cword-2]) match $pprev { with --setspeeddial _gnokii_memory_type return with --getsms|--deletesms|--getmms|--deletemms|--getphonebook|\ --writetodo|--writecalendarnote # TODO: start number return with --gettodo|--getcalendarnote setglobal COMPREPLY = '( '$( compgen -W '{1..9} end --vCal' -- "$cur" ) ) return with --deletecalendarnote setglobal COMPREPLY = '( '$( compgen -W '{1..9} end' -- "$cur" ) ) return with --divert setglobal COMPREPLY = '( '$( compgen -W 'register enable query disable erasure' -- "$cur" ) ) return } } # third level completion if [[ $((cword-3)) -ge 1 && ${words[cword-3]} =~ --* ]] { set tprev = $(words[cword-3]) match $tprev { with --deletesms|--deletemms setglobal COMPREPLY = '( '$( compgen -W 'end' -- "$cur" ) ) return with --getphonebook|--writetodo|--writecalendarnote setglobal COMPREPLY = '( '$( compgen -W '{1..9} end' -- "$cur" ) ) return with --gettodo|--getcalendarnote [[ ${words[cword-1]} == end ]] && \ setglobal COMPREPLY = '( '$( compgen -W '--vCal' -- "$cur" ) ) return with --divert setglobal COMPREPLY = '( '$( compgen -W '--type' -- "$cur" ) ) return } } # fourth level completion if [[ $((cword-4)) -ge 1 && ${words[cword-4]} =~ --* ]] { set fprev = $(words[cword-4]) match $fprev { with --getphonebook setglobal COMPREPLY = '( '$( compgen -W '--raw --vcard --ldif' -- "$cur" ) ) return with --divert setglobal COMPREPLY = '( '$( compgen -W 'all busy noans outofreach notavail' \ -- "$cur" ) ) return } } # safer to use LANG=C var all_cmd = $[ env LANG=C _parse_help $1 "--help all] # these 2 below are allowed in combination with others var main_cmd = $[ echo $all_cmd | grep -v -- '--config\|--phone] # don't provide main command completions if one is # already on the command line [[ $COMP_LINE =~ $( tr ' ' '\b|'<<<$main_cmd ) ]] && return setglobal COMPREPLY = '( '$( compgen -W "$all_cmd" -- "$cur" ) ) } && complete -F _gnokii gnokii # ex: ts=4 sw=4 et filetype=sh