# bash completion for ArchLinux rc.d # have rc.d && _rc.d() { local cur prev COMPREPLY=() _get_comp_words_by_ref cur prev declare -A actions for d in $(rc.d list | sed -e 's+^\[.*\] ++g'); do [ "$d" == "sshd" ] && continue for a in $(rc.d usage $d 2>/dev/null | sed -e 's/.*{\(.*\)}/\1/g' -e 's/|/ /g'); do actions["$a"]+="$(basename $d) " done done case $COMP_CWORD in 1) WORDS="${!actions[@]}" COMPREPLY=( $(compgen -W "help list $WORDS" -- "$cur") ) ;; 2) case "$prev" in stop | restart) COMPREPLY=( $(compgen -W "$(rc.d list | grep 'STARTED' | sed 's+^\[.*\] ++g' )" -- "$cur") ) ;; start) COMPREPLY=( $(compgen -W "$(rc.d list | grep 'STOPPED' | sed 's+^\[.*\] ++g' )" -- "$cur") ) ;; *) WORDS="${actions[$prev]}"; COMPREPLY=( $(compgen -W "$WORDS" -- "$cur") ) ;; esac ;; esac return 0 } && complete -F _rc.d rc.d