# bash completion for wvdial -*- shell-script -*- proc _wvdial { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return match $prev { with --config _filedir return 0 } $split && return var config = '', i = '', IFS = '$'\n'' match $cur { with -* setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace with * # start with global and personal config files set config = ""/etc/wvdial.conf"$'\n'"$HOME/.wvdialrc"" # replace with command line config file if present for (( i=1; i < cword; i++ )); do if [[ "${words[i]}" == "--config" ]]; then config=${words[i+1]} break fi done # parse config files for sections and # remove default section setglobal COMPREPLY = '( '$( sed -ne "s|^\[Dialer \($cur.*\)\]$|\1|p" $config \ 2>/dev/null | command grep -v '^Defaults$')) # escape spaces setglobal COMPREPLY = $(COMPREPLY// /\\ ) } } && complete -F _wvdial wvdial # ex: ts=4 sw=4 et filetype=sh