[Bash-completion-commits] [SCM] bash-completion branch, master, updated. fd8ade00774b26ccfb3466f58c4d67cd09b2af15
Guillaume Rousse
Guillaume.Rousse at inria.fr
Sun Nov 7 00:16:25 UTC 2010
The following commit has been merged in the master branch:
commit 2d58e69ef9a253726c0a7bbe5d5a201e10308565
Author: Guillaume Rousse <Guillaume.Rousse at inria.fr>
Date: Sat Nov 6 23:54:17 2010 +0100
rework to match original bash function more closely, including options completion
diff --git a/completions/helpers/perldoc b/completions/helpers/perldoc
index 6e7a16d..6d91dbd 100755
--- a/completions/helpers/perldoc
+++ b/completions/helpers/perldoc
@@ -57,8 +57,7 @@ sub get_package_suggestions {
return @suggestion;
}
-sub get_function_suggestions {
- my ( $func ) = @_;
+sub get_functions {
my $perlfunc;
for ( @INC, undef ) {
@@ -69,24 +68,51 @@ sub get_function_suggestions {
open my $fh, '<', $perlfunc or return;
- my @suggestion;
+ my @functions;
my $nest_level = -1;
while ( <$fh> ) {
next if 1 .. /^=head2 Alphabetical Listing of Perl Functions$/;
++$nest_level if /^=over/;
--$nest_level if /^=back/;
next if $nest_level;
- push @suggestion, /^=item (-?\w+)/;
+ push @functions, /^=item (-?\w+)/;
}
- my $func_rx = qr/\A${\quotemeta $func}/;
+ return @functions;
+}
+
+sub filter {
+ my ($word, @list) = @_;
+
+ my $pattern = qr/\A${\quotemeta $word}/;
+
+ return grep { /$pattern/ } @list;
+}
- return grep { /$func_rx/ } @suggestion;
+sub get_suggestions {
+ my (@args) = @_;
+ my $word = pop @args;
+
+ if (@args) {
+ if ($args[-1] eq '-f') {
+ return filter(
+ $word,
+ get_functions
+ );
+ }
+ }
+
+ if ($word =~ /^-/) {
+ return filter(
+ $word,
+ qw/-h -D -t -u -m -l -F -i -v -V -T -r -d -o -M -w -n -X -L/
+ );
+
+ } else {
+ return get_package_suggestions($word);
+ }
}
-my ( $cmd, @arg ) = get_command_line();
-my $word = pop @arg;
+my ($cmd, @args) = get_command_line();
-print "$_\n" for ( @arg and @arg[-1] eq '-f' )
- ? get_function_suggestions( $word )
- : get_package_suggestions( $word );
+print "$_\n" for get_suggestions(@args);
--
bash-completion
More information about the Bash-completion-commits
mailing list