Closes Alioth #311614 Globbing might occur if $cur contains one of these globbing characters: * ? [ ] The bug becomes apparent: On Cygwin if the glob-string contains backslashes as well, causing a warning (Cygwin >= 1.7): MS-DOS style path detected: ... Preferred POSIX equivalent is: ... CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames On Linux, using strace, you can see bash-completion doing an unnecessary `open' system call. Steps to reproduce on Linux using `strace': Environment: Linux, bash-completion-1.0 1. Start bash with bash-completion loaded and find out PID ($$): $ echo $$ MYPID 2. In a second bash shell, `strace' the above PID: $ strace -e trace=open -f -o strace.log -p MYPID 3. Within the first bash shell, type: $ cur="?"; _kernel_versions 4. In the second bash shell, type ^C to quick `strace'. 5. Check `strace.log', here you can see bash accessing something it shouldn't: ... open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3 ... 6. The above call to `open' disappears if $cur in _kernel_versions gets quoted, and you repeat the steps above: _kernel_versions() { COMPREPLY=( $( compgen -W '$( command ls /lib/modules )' -- "$cur" ) ) }
120 lines
4.0 KiB
Bash
120 lines
4.0 KiB
Bash
# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
|
|
# ex: ts=8 sw=8 noet filetype=sh
|
|
#
|
|
# bash completion for perl
|
|
|
|
have perl &&
|
|
{
|
|
_perlmodules()
|
|
{
|
|
COMPREPLY=( $( compgen -P "$prefix" -W "$( perl -e 'sub mods { my ($base,$dir)=@_; return if $base !~ /^\Q$ENV{cur}/; chdir($dir) or return; for (glob(q[*.pm])) {s/\.pm$//; print qq[$base$_\n]}; mods(/^(?:[.\d]+|$Config{archname}-$Config{osname}|auto)$/ ? undef : qq[${base}${_}\\\\:\\\\:],qq[$dir/$_]) for grep {-d} glob(q[*]); } mods(undef,$_) for @INC;' )" -- "$cur" ) )
|
|
}
|
|
|
|
_perl()
|
|
{
|
|
local cur prev prefix temp
|
|
local optPrefix optSuffix
|
|
|
|
COMPREPLY=()
|
|
cur=`_get_cword`
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
prefix=""
|
|
|
|
# If option not followed by whitespace, reassign prev and cur
|
|
if [[ "$cur" == -?* ]]; then
|
|
temp=$cur
|
|
prev=${temp:0:2}
|
|
cur=${temp:2}
|
|
optPrefix=-P$prev
|
|
optSuffix=-S/
|
|
prefix=$prev
|
|
fi
|
|
|
|
# only handle module completion for now
|
|
case "$prev" in
|
|
-I|-x)
|
|
local IFS=$'\t\n'
|
|
COMPREPLY=( $( compgen -d $optPrefix $optSuffix -- "$cur" ) )
|
|
return 0
|
|
;;
|
|
-m|-M)
|
|
_perlmodules
|
|
return 0
|
|
;;
|
|
esac
|
|
|
|
if [[ "$cur" == -* ]]; then
|
|
COMPREPLY=( $( compgen -W '-C -s -T -u -U -W -X -h -v -V -c -w -d \
|
|
-D -p -n -a -F -l -0 -I -m -M -P -S -x -i -e ' -- "$cur" ) )
|
|
else
|
|
_filedir
|
|
fi
|
|
}
|
|
complete -F _perl $nospace $filenames perl
|
|
|
|
_perldoc()
|
|
{
|
|
local cur prev prefix temp
|
|
|
|
COMPREPLY=()
|
|
cur=`_get_cword`
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
prefix=""
|
|
|
|
# completing an option (may or may not be separated by a space)
|
|
if [[ "$cur" == -?* ]]; then
|
|
temp=$cur
|
|
prev=${temp:0:2}
|
|
cur=${temp:2}
|
|
prefix=$prev
|
|
fi
|
|
|
|
# complete builtin perl functions
|
|
case $prev in
|
|
-f)
|
|
COMPREPLY=( $( compgen -W 'chomp chop chr crypt hex index lc \
|
|
lcfirst length oct ord pack q qq reverse rindex sprintf \
|
|
substr tr uc ucfirst y m pos quotemeta s split study qr abs \
|
|
atan2 cos exp hex int log oct rand sin sqrt srand pop push \
|
|
shift splice unshift grep join map qw reverse sort unpack \
|
|
delete each exists keys values binmode close closedir \
|
|
dbmclose dbmopen die eof fileno flock format getc print \
|
|
printf read readdir rewinddir seek seekdir select syscall \
|
|
sysread sysseek syswrite tell telldir truncate warn write \
|
|
pack read syscall sysread syswrite unpack vec -X chdir chmod \
|
|
chown chroot fcntl glob ioctl link lstat mkdir open opendir \
|
|
readlink rename rmdir stat symlink umask unlink utime caller \
|
|
continue do dump eval exit goto last next redo return \
|
|
sub wantarray caller import local my our package use defined \
|
|
formline reset scalar undef \
|
|
alarm exec fork getpgrp getppid getpriority kill pipe qx \
|
|
setpgrp setpriority sleep system times wait waitpid \
|
|
import no package require use bless dbmclose dbmopen package \
|
|
ref tie tied untie use accept bind connect getpeername \
|
|
getsockname getsockopt listen recv send setsockopt shutdown \
|
|
socket socketpair msgctl msgget msgrcv msgsnd semctl semget \
|
|
semop shmctl shmget shmread shmwrite endgrent endhostent \
|
|
endnetent endpwent getgrent getgrgid getgrnam getlogin \
|
|
getpwent getpwnam getpwuid setgrent setpwent endprotoent \
|
|
endservent gethostbyaddr gethostbyname gethostent \
|
|
getnetbyaddr getnetbyname getnetent getprotobyname \
|
|
getprotobynumber getprotoent getservbyname getservbyport \
|
|
getservent sethostent setnetent setprotoent setservent \
|
|
gmtime localtime time times' -- "$cur" ) )
|
|
return 0
|
|
;;
|
|
esac
|
|
|
|
if [[ "$cur" == -* ]]; then
|
|
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}" | grep perl )' -- "$cur" ) )
|
|
fi
|
|
fi
|
|
}
|
|
complete -F _perldoc $default perldoc
|
|
}
|