Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH Completion for _yum (contains FIXMEs)



I've taken a look at the FIXMEs — answers below — but haven't done
a full review.

Paul Seyfert wrote on Wed, Oct 26, 2016 at 19:37:21 +0200:
> There are two fixmes for which I'd need suggestions. Some of the yum
> history commands take IDs of past transactions. Single IDs or ID ranges,
> e.g.
> 
>    yum history list 3..16
> 
> where IDs range from 1 to
> `yum history stats | grep Transactions | sed "s/.*: //"`
> 
> At the moment, there are just '1' '2' '3' '1..2' '1..3' '2..3' hard
> coded as place holders. I don't know what's a sensible way to provide
> a completion for these.

Something like this:
.
    _id_ranges() { if compset -P '*..'; then _ids; else _ids -S ..; fi } 
.
where _ids() is a function that adds "1" "2" "3" as completions.

There should be examples of this in the revision ranges handling in
_git/_hg/_subversion.

> +    if [[ -n "${ID_commands[(r)$words[2]]}" ]]; then
> +      description+="IDs"
> +      # FIXME: hard coded IDs just a draft
> +      suggests+=('last' 'all' 1 2 3)
> +    fi
> +    if [[ -n "${ID_range_commands[(r)$words[2]]}" ]]; then
> +      if [[ -n $description ]] ; then description+=", "; fi
> +      description+="ID ranges"
> +      # FIXME: hard coded IDs just a draft
> +      suggests+=('1..2' '2..3' '1..3')
> +    fi
> +    if [[ -n "${package_commands[(r)$words[2]]}" ]]; then
> +      if [[ -n $description ]] ; then description+=", "; fi
> +      description+="packages"
> +      _yum_installed_pkgs
> +      suggests+=($_installed_pkgs)
> +    fi
> +    if [[ ! -n $description ]] ; then
> +      _message "unknown expansion for: yum history $words[2]"
> +    else
> +      _describe $description suggests
> +    fi
> +  fi

This looks like it would be better written with _alternative:

    alts=()
    [[ -n "${ID_range_commands[(r)$words[2]]}" ]] && alts+=( 'id-ranges:id ranges:_id-ranges' )
    [[ -n "${package_commands[(r)$words[2]]}" ]] && alts+=( 'packages:packages:...' )
    ⋮
    (( ${+alts[1]} )) && _alternative "$alts[@]"

To see the difference, set the «group-name» style to «''» (and
optionally the «format» style to something with «%d» in it).  You can
see this in «ssh <TAB>» too (compare with/without those two styles).

Let's see what the other devs have to say about the rest of the patch.

Cheers,

Daniel



Messages sorted by: Reverse Date, Date, Thread, Author