Closed Freed-Wu closed 1 year ago
I generate zsh completion from --help. In fact, we can also generate it from pod like this:
--help
open my $in, '<' . <*.pod> or die "Can't find `*.pod'!"; my @lines = (); my @pods = (); my $sep = $/; $/ = '=item B<-'; while (<$in>) { push @pods, $_; # strip \..* s/^([^.]*)\..*/$1/s; # remove pod mark B<>, I<> s/^/B<-/; s/B<(-(?:.|-[^>]+))>/$1/g; s/I<([^>]*)>/$1/g; # convert '-?, --help' to '{-?,--help}' s/, -/,-/g; s!(-[^= ]+,[^=$sep]+)(=|$sep)!{$1}$2!; # convert '--option=value XXXX' to '--option"[XXX]:value"' s/=([^$sep]+)$sep$sep(.*)/"[$2]:$1"/s; # convert '--option XXXX' to '--option"[XXX]"' s/$sep$sep(.*)/"[$1]"/s; # change `--help` to `'(- : *)'--help` s/(.*and exit)/'(- : *)'$1/; s/(:shell)/$1:(zsh)/; push @lines, $_; } $/ = $sep; # not $\, zsh only support '\n' my $options = join "\n ", @lines[ 1 .. $#lines ]; $code .= <<EOF; sub print_completion_zsh() { print <<_EOF; #compdef \$MAIN local options=( $options ) _arguments -S -s \\\$options '*:: :_files' _EOF }
Had a nearly finished version before this pull request, so I finished it and pushed it instead. Closes #6.
I generate zsh completion from
--help
. In fact, we can also generate it from pod like this: