aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-12-30 19:02:10 +0100
committerJay Berkenbilt <ejb@ql.org>2022-01-06 00:13:25 +0100
commit0f1ffa1215ae2ca28e9ff9726313853cba021737 (patch)
tree6951b3c6ca74a0c104cc7fb5304900f1936cda02 /libtests
parent4782b5904f2cddc7ecda86abc0590a2ff8715b33 (diff)
downloadqpdf-0f1ffa1215ae2ca28e9ff9726313853cba021737.tar.zst
Move bash/zsh completion helpers to libtests/arg_parser
Diffstat (limited to 'libtests')
-rw-r--r--libtests/qtest/arg_parser/completion_helpers.pm36
1 files changed, 36 insertions, 0 deletions
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;