[Bash-completion-devel] Bug#463969: bash-completion: The bug seems to still present in 20080617.5
Morita Sho
morita-pub-en-debian at inz.sakura.ne.jp
Wed Jun 25 19:07:10 UTC 2008
On 06/26/2008 02:58 AM, David Paleino wrote:
> On Thu, 26 Jun 2008 02:52:45 +0900, Morita Sho wrote:
>> I wanted to fix the problem that gdb completion completes Bash's built-in
>> commands, functions and aliases.
>> but it is slightly hard to implement...
>
> Yes :)
> The fact is, you can't "exclude" completions from "compgen". Look at the "-b"
> switch (or -A builtin, it's the same). There should be something like:
>
> compgen -c !-b [..]
>
> (i.e. complete commands but not bash builtins...)
>
> I'll think a bit about this -- but I won't go mad since it would be a minor
> feature, really :)
Exactly. But I made it. :)
If $cur contains any slashes, compgen -c just completes only executables and
directory names. No need to taking care of Bash's built-ins.
The problem is when $cur contains no slashes. I need to get only program names.
To solve this problem, I chosen to use find(1). find(1) can be used to retrieve
program names in the current directory and $PATH.
[...]
if [ $COMP_CWORD -eq 1 ]; then
local IFS
if [[ "$cur" == */* ]]; then
# compgen -c works as expected if $cur contains any slashes.
IFS=$'\n'
COMPREPLY=( $( compgen -d -c -- "$cur" ) )
else
# otherwise compgen -c contains Bash's built-in commands, functions and
aliases.
# Thus we need to retrieve program names manually.
IFS=":"
local path_array=( $(echo "$PATH") )
IFS=$'\n'
COMPREPLY=( $( compgen -d -W '$(find "${path_array[@]}" . \
-mindepth 1 -maxdepth 1 -not -type d -executable -printf "%f\\n")' --
"$cur" ) )
fi
elif [ $COMP_CWORD -eq 2 ]; then
[...]
Regards,
--
Morita Sho <morita-pub-en-debian at inz.sakura.ne.jp>
More information about the Bash-completion-devel
mailing list