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

Re: PATCH: update ansible completion to 2.9



Oliver Kiddle wrote on Wed, 08 Jul 2020 13:31 +0200:
> For 2.9.10 to be precise but I don't think much changes in the minor
> patch releases.
> Most of the changes appear to be with ansible-galaxy and ansible-vault,
> neither of which I use so much. Completing tags is new. Unfortunately
> the playbook tends to come last on the command-line after you've
> specified the tags so it isn't really possible to get the exact playbook
> and parse it for includes and roles. But completion for tags is too
> useful to leave out completely.
> 
> Oliver
> 
> +++ b/Completion/Unix/Command/_ansible
> @@ -232,27 +231,68 @@ case $state in
> +  tags)
> +    # The recursive glob here is questionable and perhaps there should be a style.
> +    _sequence _wanted tags expl tag compadd - \
> +        ${(s.,.)${(j.,.)${(M)${(f)"$(cat **/*.yml)"}:# #tags:*}#*: }} && ret=0
> +  ;;

Review of this block:

1. Missing end-of-options guard

2. Agree that recursive glob is questionable.  It's effectively
unbounded work, to say nothing of NFS mounts, /zfs/.snapshot/ dirs, and
the like.  I'm not sure that should be the default behaviour.  One
alternative suggestion is a zstyle whose value is a list of files to
grep.  Another POV: if the yml files are in version control, then the
VCS could be queried (e.g., `git ls-tree -r ./`).  That might be useful
in other completions too.

3. Add the (N) glob qualifier?

4. As written, this slurps "$(cat **/*.yml)" into a giant string
literal, then splits it into an array in memory, etc..  I suspect it
would be a lot faster to just use grep(1) or sed(1), since we're
forking anyway.

Haven't had time to review blocks other than this one, sorry.  (Might
do so later if I have time, but don't wait for me.)

Cheers,

Daniel



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