gugod / App-perlbrew

Manage perl installations in your $HOME
https://perlbrew.pl
Other
719 stars 216 forks source link

zsh completion #146

Open dbb opened 13 years ago

dbb commented 13 years ago

I've made a zsh completion function for Perlbrew: https://github.com/dbb/zsh-stuff/blob/master/_perlbrew

I'm still fine-tuning it, but it is operational now. Features include:

The function actually uses perlbrew to list perls, but I had to rely on an external program (I chose perl over sed) to strip out superfluous data in the output, like the asterisk next to the current perl in use, the 'i' before installed available perls, and the version number after /usr/bin/perl. The only problem with this is that it takes an extra second or so to generate the completion list. I suppose it might be a few milliseconds faster if I used sed instead of perl, but I really don't have the patience to learn how to use sed.

If you could add a new command like possible-perls or something that would only print the names of the perls and nothing else, it would really speed up the completion process.

I hope all members of the intersection of perlbrew users and zsh users will find this useful.

telemachus commented 13 years ago

Not sure how much of this would apply to zsh, but this is how I do completion of potential Perl interpreters for Bash completion of Perlbrew:

_perls()
{
    local cur perls
    local ROOT=${PERLBREW_ROOT:-$HOME/perl5/perlbrew}
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    perls=($ROOT/perls/perl-*)
    # remove all but the final part of the name
    perls="${perls[@]##*/} /usr/bin/perl"

    COMPREPLY=( $( compgen -W "${perls}" -- ${cur} ) )
}

This doesn't apply to install since it only discovers interpreters that are already installed.

dbb commented 13 years ago

That's what $PERLBREW_ROOT/perls/*(:t) is for-- (:t) is sort of like basename. I guess I could add a conditional block to check ~/perl5 if $PERLBREW_ROOT is undefined, but it seems like it should be defined if perlbrew is in use: https://github.com/dbb/zsh-stuff/commit/aecbae433e245c8d9faeb8d3a0f5a80f0492f58d