diff options
Diffstat (limited to 'completions/perl')
-rw-r--r-- | completions/perl | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/completions/perl b/completions/perl index 843e249b..a67c7699 100644 --- a/completions/perl +++ b/completions/perl @@ -1,26 +1,26 @@ -# bash completion for perl +# bash completion for perl -*- shell-script -*- -have perl && -{ _perlmodules() { - COMPREPLY=( $( compgen -P "$prefix" -W "$( $1 ${BASH_SOURCE[0]%/*}/helpers/perl modules $cur )" -- "$cur" ) ) + COMPREPLY=( $( compgen -P "$prefix" -W \ + "$( ${1:-perl} ${BASH_SOURCE[0]%/*}/../helpers/perl modules $cur )" \ + -- "$cur" ) ) __ltrim_colon_completions "$prefix$cur" } _perlfunctions() { - COMPREPLY=( $( compgen -P "$prefix" -W "$( ${BASH_SOURCE[0]%/*}/helpers/perl functions $cur )" -- "$cur" ) ) + COMPREPLY=( $( compgen -P "$prefix" -W \ + "$( ${1:-perl} ${BASH_SOURCE[0]%/*}/../helpers/perl functions $cur )" \ + -- "$cur" ) ) } _perl() { - local cur prev prefix temp - local optPrefix optSuffix + local cur prev words cword + _init_completion -n : || return - COMPREPLY=() - _get_comp_words_by_ref -n : cur prev - prefix="" + local prefix="" temp optPrefix optSuffix # If option not followed by whitespace, reassign prev and cur if [[ "$cur" == -?* ]]; then @@ -38,13 +38,13 @@ _perl() ;; -I|-x) local IFS=$'\n' - _compopt_o_filenames + compopt -o filenames COMPREPLY=( $( compgen -d $optPrefix $optSuffix -- "$cur" ) ) return 0 ;; -m|-M) temp="${cur#-}" - prefix="$prefix${cur%$temp}" + prefix+="${cur%$temp}" cur="$temp" _perlmodules $1 return 0 @@ -52,7 +52,7 @@ _perl() -V) if [[ $cur == :* ]]; then temp="${cur##+(:)}" - prefix="$prefix${cur%$temp}" + prefix+="${cur%$temp}" local IFS=$'\n' COMPREPLY=( $( compgen -P "$prefix" -W \ '$( $1 -MConfig -e "print join \"\\n\", @@ -78,16 +78,15 @@ _perl() else _filedir fi -} +} && complete -F _perl perl _perldoc() { - local cur prev prefix temp + local cur prev words cword + _init_completion -n : || return - COMPREPLY=() - _get_comp_words_by_ref -n : cur prev - prefix="" + local prefix="" temp # completing an option (may or may not be separated by a space) if [[ "$cur" == -?* ]]; then @@ -97,10 +96,13 @@ _perldoc() prefix=$prev fi + local perl="${1%doc}" + [[ $perl == $1 ]] || ! type $perl &>/dev/null && perl= + # complete builtin perl functions case $prev in -f) - _perlfunctions "$cur" + _perlfunctions $perl return 0 ;; esac @@ -109,23 +111,19 @@ _perldoc() COMPREPLY=( $( compgen -W '-h -v -t -u -m -l -F -X -f -q' -- "$cur" )) else # return available modules (unless it is clearly a file) - if [[ "$cur" != */* ]]; then - _perlmodules - COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W \ - '$( PAGER=/bin/cat man perl | \ - sed -ne "/perl.*Perl overview/,/perlwin32/p" | \ - awk "\$NF=2 { print \$1}" | command grep perl )' -- "$cur" ) ) + if [[ "$cur" != @(*/|[.~])* ]]; then + _perlmodules $perl + if [[ $cur == p* ]]; then + COMPREPLY+=( $( compgen -W \ + '$( PERLDOC_PAGER=/bin/cat "$1" -u perl | \ + sed -ne "/perl.*Perl overview/,/perlwin32/p" | \ + awk "\$NF=2 && \$1 ~ /^perl/ { print \$1 }" )' \ + -- "$cur" ) ) + fi fi _filedir 'p@(l|m|od)' fi -} +} && complete -F _perldoc -o bashdefault perldoc -} -# Local variables: -# mode: shell-script -# sh-basic-offset: 4 -# sh-indent-comment: t -# indent-tabs-mode: nil -# End: # ex: ts=4 sw=4 et filetype=sh |