| 1 | package Bash::Completion::Plugins::Sqitch; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use parent 'Bash::Completion::Plugin'; | ||
| 6 | use Bash::Completion::Utils qw{command_in_path}; | ||
| 7 | use Bash::Completion::RequestX::Sqitch; | ||
| 8 | |||
| 9 | our $VERSION = '0.01'; | ||
| 10 | |||
| 11 | sub complete { | ||
| 12 | my ($self, $r) = @_; | ||
| 13 | |||
| 14 | # this is the word bash is trying to complete | ||
| 15 | my $word = $r->word; | ||
| 16 | |||
| 17 | # extended request for the sqitch command | ||
| 18 | my $rx = Bash::Completion::RequestX::Sqitch->new(request => $r); | ||
| 19 | |||
| 20 | $r->candidates(prefix_match($word, @{$rx->candidates})); | ||
| 21 | } | ||
| 22 | |||
| 23 | # Bash::Completion::Utils version of prefix_match is broken in that it doesn't | ||
| 24 | # quote the meta characters in variables used in regular expressions. | ||
| 25 | sub prefix_match { | ||
| 26 | my $prefix = shift; | ||
| 27 | |||
| 28 | return grep { /^\Q$prefix\E/ } @_; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub should_activate { | ||
| 32 | return [grep { command_in_path($_) } ('sqitch')]; | ||
| 33 | } | ||
| 34 | |||
| 35 | 1; | ||
| 36 | |||
| 37 | __END__ |