# htpasswd(1) completion -*- shell-script -*- proc _htpasswd { var cur = '', prev = '', words = '', cword = '' _init_completion || return var i = '', o = '0' # $o is index of first non-option argument for (( i=1; i <= cword; i++ )); do case ${words[i]} in -*n*) return ;; -*) ;; *) o=$i ; break ;; esac done if [[ $o -eq 0 || $o -eq $cword ]] { if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) return } # Password file (first non-option argument) _filedir } elif [[ $o -eq $cword-1 ]] { # Username (second non-option argument) setglobal COMPREPLY = '( '$( compgen -W \ '$( cut -d: -f1 "${words[o]}" 2>/dev/null )' -- "$cur" ) ) } } && complete -F _htpasswd htpasswd # ex: ts=4 sw=4 et filetype=sh