diff options
-rw-r--r-- | Completion/User/_perl_basepods | 30 | ||||
-rw-r--r-- | Completion/User/_perl_builtin_funcs | 29 | ||||
-rw-r--r-- | Completion/User/_perl_modules | 47 | ||||
-rw-r--r-- | Completion/User/_perldoc | 23 |
4 files changed, 129 insertions, 0 deletions
diff --git a/Completion/User/_perl_basepods b/Completion/User/_perl_basepods new file mode 100644 index 000000000..f4e70382b --- /dev/null +++ b/Completion/User/_perl_basepods @@ -0,0 +1,30 @@ +#autoload +# +# _perl_basepods - zsh completion function +# +# Adam Spiers <adam@spiers.net> +# +# Calculate all installed Perl base pods (perlfunc, perlfaq etc.). +# The result is cached for future use. +# + +if [[ ${+_perl_basepods} -eq 0 ]]; then + typeset -agU _perl_basepods + + if which basdepods >/dev/null; then + _perl_basepods=( ${$(basepods):t:r} ) + else + local podpath + podpath=$(perl -MConfig -e 'print "$Config{installprivlib}/pod"') + if [[ ! -e $podpath/perl.pod ]]; then + echo "Couldn't find perl.pod from Config.pm; giving up." + return 1 + else + cd $podpath + _perl_basepods=( *.pod(:r:t) ) + cd $OLDPWD + fi + fi +fi + +compadd - $_perl_basepods diff --git a/Completion/User/_perl_builtin_funcs b/Completion/User/_perl_builtin_funcs new file mode 100644 index 000000000..a8facda08 --- /dev/null +++ b/Completion/User/_perl_builtin_funcs @@ -0,0 +1,29 @@ +#autoload +# +# _perl_builtin_funcs - zsh completion function +# +# Adam Spiers <adam@spiers.net> +# +# Calculate all built-in Perl functions. The result is cached +# for future use. +# + +if [[ ${+_perl_builtin_funcs} -eq 0 ]]; then + typeset -agU _perl_builtin_funcs + local perlfunc + + if perlfunc=`man -w perlfunc 2>&1`; then + _perl_builtin_funcs=( `perl -lne ' + $in_funcs++, next if /Alphabetical/; \ + next unless $in_funcs; \ + if (/^\.Ip "(\w+)/) { \ + print $1 unless $func{$1}; $func{$1}++ \ + }' $perlfunc` + ) + else + echo "Couldn't find perlfunc man page; giving up." + return 1 + fi +fi + +compadd - $_perl_builtin_funcs diff --git a/Completion/User/_perl_modules b/Completion/User/_perl_modules new file mode 100644 index 000000000..c909055ba --- /dev/null +++ b/Completion/User/_perl_modules @@ -0,0 +1,47 @@ +#compdef pmpath pmvers pmdesc pmload pmexp pmeth pmls pmcat pman pmfunc podgrep podtoc podpath +# +# +# _perl_modules - zsh completion function +# +# Adam Spiers <adam@spiers.net> +# +# Calculate all installed Perl modules. The result is cached +# for future use. +# +# Bugs: +# - can't cope with multiple installs of Perl + +# Change this if you have pminst and want to use it. The zsh code +# actually produces better results because pminst misses modules of +# the form Foo/bar/Baz.pm through its clumsy -d && /^[A-Z]/ && prune +# algorithm (the zsh code does almost the same, but only misses modules +# which don't begin with an uppercase letter). +local try_to_use_pminst=0 + +if [[ ${+_perl_modules} -eq 0 ]]; then + if [[ $try_to_use_pminst -ne 0 ]] && which pminst >/dev/null; then + _perl_modules=( $(pminst) ) + else + local inc libdir new_pms + inc=( $( perl -e 'print "@INC"' ) ) + typeset -agU _perl_modules # _perl_modules is global, no duplicates + _perl_modules=( ) + + for libdir in $inc; do + # Ignore cwd - could be too expensive e.g. if we're near / + if [[ $libdir == '.' ]]; then break; fi + + # Find all modules + cd $libdir + new_pms=( {[A-Z]*/**/,}*.pm(N) ) + cd $OLDPWD + + # Convert to Perl nomenclature + new_pms=( ${new_pms:r:fs#/#::#} ) + + _perl_modules=( $new_pms $_perl_modules ) + done + fi +fi + +compadd - $_perl_modules diff --git a/Completion/User/_perldoc b/Completion/User/_perldoc new file mode 100644 index 000000000..cd5383a45 --- /dev/null +++ b/Completion/User/_perldoc @@ -0,0 +1,23 @@ +#compdef perldoc +# +# +# _perldoc - zsh completion function for perldoc +# +# Adam Spiers <adam@spiers.net> +# +# Behaviour should be roughly equivalent to: +# compctl -k perl_modules -k perl_basepods -f +# -x 'c[-1,-f]' -k perl_funcs -- +# + -k man_pages +# perldoc + +if [[ $CURRENT -eq 3 && $words[2] == '-f' ]]; then + _perl_builtin_funcs +elif [[ $CURRENT -eq 3 && $words[2] == '-q' ]]; then + zle -R "I can't read your mind!" +else + _perl_modules + _perl_basepods + _path_files -/ -g '*.(pod|pm)' +fi + |