From 0f1ffa1215ae2ca28e9ff9726313853cba021737 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 30 Dec 2021 13:02:10 -0500 Subject: Move bash/zsh completion helpers to libtests/arg_parser --- libtests/qtest/arg_parser/completion_helpers.pm | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 libtests/qtest/arg_parser/completion_helpers.pm (limited to 'libtests') diff --git a/libtests/qtest/arg_parser/completion_helpers.pm b/libtests/qtest/arg_parser/completion_helpers.pm new file mode 100644 index 00000000..328673e5 --- /dev/null +++ b/libtests/qtest/arg_parser/completion_helpers.pm @@ -0,0 +1,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; -- cgit v1.2.3-54-g00ecf