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

Re: todo.sh completion



Thank you for the quick answer and fix Peter ! I just built zsh from sources
and it works fine now. By the way, for users who would want to build Zsh
from sources on Ubuntu(/Debian?), I put the steps here:
http://gist.github.com/715855.

Regards,
Julien

2010/11/25 Peter Stephenson <Peter.Stephenson@xxxxxxx>

> On Thu, 25 Nov 2010 15:34:56 +0100
> Julien Nicoulaud <julien.nicoulaud@xxxxxxxxx> wrote:
> > OK, I checked my zshrc and it turns out this was breaking the
> > completion script:
> >
> >     autoload -U zsh-mime-setup && zsh-mime-setup
>
> Useful research, thank you.
>
> > I guess this has to do with todo.sh ending with ".sh", since every
> > others completion scripts work fine.
>
> Yes, what should happen is that _zsh-mime-handler finds it shouldn't be
> handling todo.sh in this case and despatching to normal completion
> instead.  There were some (at least three) glitches with this.  This
> fixes the ones I found.
>
> - zsh-mime-handler didn't handle the "-l" option for stuff it passed
> through without handling.  (This should simply end up with $words
> being pruned from the front.)
>
> - _zsh-mime-handler didn't keep empty arguments, which is what
> you get when you first try completion on a word.
>
> - _zsh-mime-handler updated $words but didn't update $CURRENT.  Best
> guess is to keep $CURRENT at the same offset from the end of $words.
>
> Index: Completion/Zsh/Function/_zsh-mime-handler
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Function/_zsh-mime-handler,v
> retrieving revision 1.1
> diff -p -u -r1.1 _zsh-mime-handler
> --- Completion/Zsh/Function/_zsh-mime-handler   23 May 2010 19:54:03 -0000
>      1.1
> +++ Completion/Zsh/Function/_zsh-mime-handler   25 Nov 2010 15:29:27 -0000
> @@ -1,9 +1,19 @@
>  #compdef zsh-mime-handler
>
> +# Given that the handler is likely to change the start of the command
> +# line, we'll try to maintain the position from the end of the words
> +# array.  Hence for example CURRENT gets decremented by one if the
> +# handler drops off the start.
> +integer end_offset=$(( ${#words} - CURRENT ))
> +
>  # zsh-mime-handler -l is supposed to print out the command line
>  # with quoting to turn it into a full executable line.  So
>  # we need to use shell splitting to turn it into words and
>  # then unquoting on those words.
> -words=(${(Q)${(z)"$(zsh-mime-handler -l ${words[2,-1]})"}})
> +words=(${(z)"$(zsh-mime-handler -l "${(@)words[2,-1]}")"})
> +# Careful unquoting: we need to keep a '' as a separate word.
> +words=("${(@Q)words}")
> +
> +(( CURRENT = ${#words} - end_offset ))
>
>  _normal
> Index: Functions/MIME/zsh-mime-handler
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Functions/MIME/zsh-mime-handler,v
> retrieving revision 1.13
> diff -p -u -r1.13 zsh-mime-handler
> --- Functions/MIME/zsh-mime-handler     8 Aug 2010 17:20:55 -0000
> 1.13
> +++ Functions/MIME/zsh-mime-handler     25 Nov 2010 15:29:27 -0000
> @@ -144,7 +144,11 @@ if [[ ! -e $1 ]]; then
>     fi
>   done
>   if [[ -z $nonex_ok ]]; then
> -    "$@"
> +    if (( list )); then
> +      print -r -- "${(q)@}"
> +    else
> +      "$@"
> +    fi
>     return
>   fi
>  fi
>
> --
> Peter Stephenson <pws@xxxxxxx>            Software Engineer
> Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
> Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ,
> UK
>
>
> Member of the CSR plc group of companies. CSR plc registered in England and
> Wales, registered number 4187346, registered office Churchill House,
> Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
>


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