aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qtest/arg_parser/completion_helpers.pm
blob: 328673e5ab02ca046cb0fca6adad5b82cf826251 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This is also used by qpdf.test.

sub bash_completion
{
    my ($x, $line, $point) = @_;
    if (! defined $point)
    {
        $point = length($line);
    }
    my $before_point = substr($line, 0, $point);
    my $first = '';
    my $sep = '';
    my $cur = '';
    if ($before_point =~ m/^(.*)([ =])([^= ]*)$/)
    {
        ($first, $sep, $cur) = ($1, $2, $3);
    }
    my $prev = ($sep eq '=' ? $sep : $first);
    $prev =~ s/.* (\S+)$/$1/;
    my $this = $first;
    $this =~ s/(\S+)\s.*/$1/;
    ['env', "COMP_LINE=$line", "COMP_POINT=$point",
     $x, $this, $cur, $prev];
}

sub zsh_completion
{
    my ($x, $line, $point) = @_;
    if (! defined $point)
    {
        $point = length($line);
    }
    ['env', "COMP_LINE=$line", "COMP_POINT=$point", $x];
}

1;