mirror of
https://github.com/mpv-player/mpv
synced 2025-02-18 13:47:04 +00:00
TOOLS/zsh.pl: don't consume extra arguments
Completion now uses "--opt=value" instead of "--opt value". Once the user presses space and starts a new argument, the option just completed is out of the picture, whether or not it was given an argument. This handles options with no arguments or optional arguments much better; previously, completing such an option would effectively disable completion for the next argument. Custom completed options such as "--ao" and friends will no longer claim to consume an extra argument.
This commit is contained in:
parent
fd09578f0f
commit
bbc005825a
28
TOOLS/zsh.pl
28
TOOLS/zsh.pl
@ -7,7 +7,7 @@ use warnings;
|
|||||||
|
|
||||||
my $mpv = $ARGV[0] || 'mpv';
|
my $mpv = $ARGV[0] || 'mpv';
|
||||||
|
|
||||||
my @opts = parse_opts("$mpv --list-options", '^ (\-\-[^\s\*]*)\*?\s*(.*)');
|
my @opts = parse_opts("$mpv --list-options", '^ (\-\-[^\s\*]*)\*?\s*(.*)', 1);
|
||||||
|
|
||||||
my @ao = parse_opts("$mpv --ao=help", '^ ([^\s\:]*)\s*: (.*)');
|
my @ao = parse_opts("$mpv --ao=help", '^ ([^\s\:]*)\s*: (.*)');
|
||||||
my @vo = parse_opts("$mpv --vo=help", '^ ([^\s\:]*)\s*: (.*)');
|
my @vo = parse_opts("$mpv --vo=help", '^ ([^\s\:]*)\s*: (.*)');
|
||||||
@ -17,7 +17,7 @@ my @vf = parse_opts("$mpv --vf=help", '^ ([^\s\:]*)\s*: (.*)');
|
|||||||
|
|
||||||
my ($opts_str, $ao_str, $vo_str, $af_str, $vf_str);
|
my ($opts_str, $ao_str, $vo_str, $af_str, $vf_str);
|
||||||
|
|
||||||
$opts_str .= qq{ '$_': \\\n} foreach (@opts);
|
$opts_str .= qq{ '$_' \\\n} foreach (@opts);
|
||||||
chomp $opts_str;
|
chomp $opts_str;
|
||||||
|
|
||||||
$ao_str .= qq{ '$_' \\\n} foreach (@ao);
|
$ao_str .= qq{ '$_' \\\n} foreach (@ao);
|
||||||
@ -98,7 +98,7 @@ EOS
|
|||||||
print $tmpl;
|
print $tmpl;
|
||||||
|
|
||||||
sub parse_opts {
|
sub parse_opts {
|
||||||
my ($cmd, $regex) = @_;
|
my ($cmd, $regex, $parsing_main_options) = @_;
|
||||||
|
|
||||||
my @list;
|
my @list;
|
||||||
my @lines = split /\n/, `$cmd`;
|
my @lines = split /\n/, `$cmd`;
|
||||||
@ -108,21 +108,29 @@ sub parse_opts {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $entry = "$1:";
|
my $entry = $1;
|
||||||
|
|
||||||
|
if ($parsing_main_options) {
|
||||||
|
$entry .= '=-';
|
||||||
|
}
|
||||||
|
|
||||||
if (defined $2) {
|
if (defined $2) {
|
||||||
my $desc = $2;
|
my $desc = $2;
|
||||||
$desc =~ s/\:/\\:/g;
|
$desc =~ s/\:/\\:/g;
|
||||||
|
|
||||||
$entry .= $desc;
|
$entry .= ':' . $desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry .= ':->ao' if ($1 eq '--ao');
|
if ($parsing_main_options) {
|
||||||
$entry .= ':->vo' if ($1 eq '--vo');
|
$entry .= ':';
|
||||||
$entry .= ':->af' if ($1 eq '--af');
|
|
||||||
$entry .= ':->vf' if ($1 eq '--vf');
|
|
||||||
|
|
||||||
push @list, $entry if ($line =~ /^$regex/)
|
$entry .= '->ao' if ($1 eq '--ao');
|
||||||
|
$entry .= '->vo' if ($1 eq '--vo');
|
||||||
|
$entry .= '->af' if ($1 eq '--af');
|
||||||
|
$entry .= '->vf' if ($1 eq '--vf');
|
||||||
|
}
|
||||||
|
|
||||||
|
push @list, $entry
|
||||||
}
|
}
|
||||||
|
|
||||||
return @list;
|
return @list;
|
||||||
|
Loading…
Reference in New Issue
Block a user