From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4422 invoked from network); 14 Nov 2000 12:47:31 -0000 Received: from sunsite.dk (HELO sunsite.auc.dk) (130.225.51.30) by ns1.primenet.com.au with SMTP; 14 Nov 2000 12:47:31 -0000 Received: (qmail 17166 invoked by alias); 14 Nov 2000 12:47:45 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 13164 Received: (qmail 17158 invoked from network); 14 Nov 2000 12:47:45 -0000 Date: Tue, 14 Nov 2000 13:47:03 +0100 From: Paul Johnson To: zsh-workers@sunsite.auc.dk Cc: adam@spiers.net Subject: PATCH: zsh and perl Message-ID: <20001114134703.D6034@sen.olsen.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i I use both zsh and perl heavily and there were a couple of things about the perldoc completion that were annoying me. 1. cd was used which called my cd function 2. with multiple versions of perl around it's nice to complete modules specific to the version of perldoc being used The following patch addresses these two issues. I'd be grateful if you would have a good look at it since my shell coding skills are not much to shout about, and comment on it or include it if you feel it's appropriate. --- _perl_modules.org Wed Oct 18 15:50:25 2000 +++ _perl_modules Tue Nov 14 13:20:10 2000 @@ -29,18 +29,30 @@ zstyle ":completion:${curcontext}:" cache-policy \ _perl_modules_caching_policy fi - - if ( [[ ${+_perl_modules} -eq 0 ]] || _cache_invalid perl_modules ) && - ! _retrieve_cache perl_modules; + + local perl=${words[0]%doc} perl_modules + if [[ -f $perl && -x $perl ]]; then + perl_modules=${perl//\\//_}_modules + elif (( ${+commands[perl]} )); then + perl=perl + perl_modules=_perl_modules + else + perl= + perl_modules=_unknown_perl_modules + fi + + if ( [[ ${(P)+perl_modules} -eq 0 ]] || _cache_invalid $perl_modules ) && + ! _retrieve_cache $perl_modules; then if zstyle -t ":completion:${curcontext}:modules" try-to-use-pminst && (( ${+commands[pminst]} )); then - _perl_modules=( $(pminst) ) + set -A $perl_modules $(pminst) else local inc libdir new_pms - if (( ${+commands[perl]} )); then - inc=( $( perl -e 'print "@INC"' ) ) + + if [[ ${+perl} -eq 1 ]]; then + inc=( $( $perl -e 'print "@INC"' ) ) else # If perl isn't there, one wonders why the user's trying to # complete Perl modules. Maybe her $path is wrong? @@ -50,8 +62,8 @@ ${(s.:.)PERL5LIB} ) fi - typeset -agU _perl_modules # _perl_modules is global, no duplicates - _perl_modules=( ) + typeset -agU $perl_modules # $perl_modules is global, no duplicates + set -A $perl_modules for libdir in $inc; do # Ignore cwd - could be too expensive e.g. if we're near / @@ -59,24 +71,24 @@ # Find all modules if [[ -d $libdir && -x $libdir ]]; then - cd $libdir + chdir $libdir new_pms=( {[A-Z]*/***/,}*.pm~*blib* ) - cd $OLDPWD + chdir $OLDPWD fi # Convert to Perl nomenclature new_pms=( ${new_pms:r:fs#/#::#} ) - _perl_modules=( $new_pms $_perl_modules ) + set -A $perl_modules $new_pms ${(P)perl_modules} done fi - _store_cache perl_modules _perl_modules + _store_cache $perl_modules ${(P)perl_modules} fi local expl - _wanted modules expl 'Perl modules' compadd "$opts[@]" -a _perl_modules + _wanted modules expl 'Perl modules' compadd "$opts[@]" -a $perl_modules } _perl_modules_caching_policy () { -- Paul Johnson - paulj@olsen.ch