Quote unquoted $cur to prevent globbing.
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" ) )
}
2009-09-25 09:36:29 +02:00
|
|
|
_path ${classes[@]} | ruby -ane 'if /^-/.../^-/ and \
|
2003-12-31 06:48:05 +00:00
|
|
|
! /^-/ and ! /^ +(class|module): / then \
|
|
|
|
print $_.split(/, |,$| +/).grep(/^[^\[]*$/).join("\n"); \
|
|
|
|
end' | sort -u )" )
|
|
|
|
fi
|
2002-04-22 05:47:13 +00:00
|
|
|
COMPREPLY=( $( compgen $prefix -W '${COMPREPLY[@]}' -- $method ) )
|
|
|
|
}
|
|
|
|
|
2003-12-31 07:18:08 +00:00
|
|
|
# needs at least Ruby 1.8.0 in order to use -W0
|
2002-04-22 05:47:13 +00:00
|
|
|
_ri()
|
|
|
|
{
|
2003-12-31 07:18:08 +00:00
|
|
|
local cur class method prefix ri_path ri_version separator IFS
|
2003-11-19 11:19:05 +00:00
|
|
|
local -a classes
|
2002-04-22 05:47:13 +00:00
|
|
|
|
|
|
|
COMPREPLY=()
|
2008-05-10 18:04:06 +02:00
|
|
|
cur=`_get_cword`
|
2002-04-22 05:47:13 +00:00
|
|
|
|
2003-12-31 06:48:05 +00:00
|
|
|
ri_path=$(type -p ri)
|
2003-12-31 07:47:38 +00:00
|
|
|
# which version of ri are we using?
|
2003-12-31 06:48:05 +00:00
|
|
|
# -W0 is required here to stop warnings from older versions of ri
|
|
|
|
# from being captured when used with Ruby 1.8.1 and later
|
|
|
|
ri_version="$(ruby -W0 $ri_path -v 2>&1)" || ri_version=integrated
|
2006-02-25 13:25:59 +00:00
|
|
|
[ "$ri_version" != "${ri_version%200*}" ] && ri_version=integrated
|
2003-12-31 06:48:05 +00:00
|
|
|
|
2002-04-22 05:47:13 +00:00
|
|
|
# need to also split on commas
|
|
|
|
IFS=$', \n\t'
|
2003-12-31 07:18:08 +00:00
|
|
|
if [[ "$cur" == [A-Z]*[#.]* ]]; then
|
|
|
|
[[ "$cur" == *#* ]] && separator=# || separator=.
|
|
|
|
# we're completing on class and method
|
|
|
|
class=${cur%$separator*}
|
|
|
|
method=${cur#*$separator}
|
2003-12-31 06:48:05 +00:00
|
|
|
classes=( $class )
|
2003-12-31 07:18:08 +00:00
|
|
|
prefix="-P $class$separator"
|
2009-07-25 13:38:42 +03:00
|
|
|
ri_get_methods
|
2003-12-31 06:48:05 +00:00
|
|
|
return 0
|
2002-04-22 05:47:13 +00:00
|
|
|
fi
|
|
|
|
|
2003-12-31 06:48:05 +00:00
|
|
|
if [ "$ri_version" = integrated ]; then
|
|
|
|
# integrated ri from Ruby 1.9
|
2004-01-04 11:38:09 +00:00
|
|
|
classes=( $( ri -c | ruby -ne 'if /^\s*$/..$stdin.eof then \
|
2003-12-31 06:48:05 +00:00
|
|
|
if /, [A-Z]+/ then print; end; end' ) )
|
|
|
|
elif [ "$ri_version" = "ri 1.8a" ]; then
|
|
|
|
classes=( $( ruby -W0 $ri_path | \
|
|
|
|
ruby -ne 'if /^'"'"'ri'"'"' has/..$stdin.eof then \
|
|
|
|
if /^ .*[A-Z]/ then print; end; end' ))
|
2003-09-17 05:39:21 +00:00
|
|
|
else
|
2003-12-31 06:48:05 +00:00
|
|
|
classes=( $( ruby -W0 $ri_path | \
|
|
|
|
ruby -ne 'if /^I have/..$stdin.eof then \
|
|
|
|
if /^ .*[A-Z]/ then print; end; end' ))
|
2003-09-17 05:39:21 +00:00
|
|
|
fi
|
|
|
|
|
Quote unquoted $cur to prevent globbing.
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" ) )
}
2009-09-25 09:36:29 +02:00
|
|
|
COMPREPLY=( $( compgen -W '${classes[@]}' -- "$cur" ) )
|
2002-04-22 05:47:13 +00:00
|
|
|
if [[ "$cur" == [A-Z]* ]]; then
|
2003-12-31 06:48:05 +00:00
|
|
|
# we're completing on class or module alone
|
|
|
|
return 0
|
2002-04-22 05:47:13 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# we're completing on methods
|
|
|
|
method=$cur
|
|
|
|
ri_get_methods
|
|
|
|
}
|
|
|
|
complete -F _ri ri
|
2009-06-08 21:22:43 +03:00
|
|
|
}
|