Subject: [bug#45004] Bash completion for ‘herd’

From: Ludovic Courtès <[email-masked]>
Date: Fri, 02 Jun 2023 15:56:11 +0200

Hi Oleg,

Oleg Pykhalov <[email-masked]> skribis:

> You could take my, which probably should be improved before merging to
> Shepherd IMHO, e.g. avoid 'awk'.
>
> ~/.local/share/bash-completion/completions/herd
>
> _herd_complete_service(){
>     local command="${COMP_WORDS[1]}"
>     local services="$(sudo herd status | awk '/*/ || /^ +/ || /^ -/ { print $NF }' | sort -u)"
>     COMPREPLY=($(compgen -W "$services" -- "${COMP_WORDS[$COMP_CWORD]}"))
> }
>
> _herd_is_command ()
> {
>     local word
>     local result="false"
>     for word in ${COMP_WORDS[*]}t
>     do
> 	if [ "$word" = "$1" ]
> 	then
> 	    result=true
> 	    break
> 	fi
>     done
>     $result
> }
>
> _herd_complete()
> {
>     local word_count=${#COMP_WORDS[*]}
>     local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
>     case $COMP_CWORD in
>         1)
> 	    if [ -z "$_herd_subcommands" ]
> 	    then
> 		# Cache the list of subcommands to speed things up.
> 		_herd_subcommands="enable disable start status stop"
> 	    fi
>             COMPREPLY=($(compgen -W "$_herd_subcommands" -- "${COMP_WORDS[$COMP_CWORD]}"))
>             ;;
>         *)
>             case $COMP_CWORD in
> 		2) _herd_complete_service;;
> 	    esac
>             ;;
>     esac
> }
>
> complete -F _herd_complete herd

Would you mind polishing a bit (as you see fit; perhaps use grep/sed
rather than Awk?) and submitting a patch for this?  I’d be happy to
apply it!

Thanks,
Ludo’.