App-shcompgen
view release on metacpan or search on metacpan
lib/App/shcompgen.pm view on Meta::CPAN
},
tcsh_global_dir => {
summary => 'Directory to put completions scripts',
schema => ['array*', of => 'str*'],
default => ['/etc/tcsh/completions'],
tags => ['common'],
},
tcsh_per_user_dir => {
summary => 'Directory to put completions scripts',
schema => ['array*', of => 'str*'],
tags => ['common'],
},
zsh_global_dir => {
summary => 'Directory to put completions scripts',
schema => ['array*', of => 'str*'],
default => ['/usr/local/share/zsh/site-functions'],
tags => ['common'],
},
zsh_per_user_dir => {
summary => 'Directory to put completions scripts',
schema => ['array*', of => 'str*'],
tags => ['common'],
},
helper_global_dir => {
summary => 'Directory to put helper scripts',
schema => ['str*'],
default => '/etc/shcompgen/helpers',
tags => ['common'],
},
helper_per_user_dir => {
summary => 'Directory to put helper scripts',
schema => ['str*'],
tags => ['common'],
},
per_option => {
summary => 'Create per-option completion script if possible',
description => <<'_',
If set to true, then attempt to create completion script that register each
option. This creates nicer completion in some shells, e.g. fish and zsh. For
example, option description can be shown.
This is possible for only some types of scripts, e.g. <pm:Perinci::CmdLine>-
(that does not have subcommands) or <pm:Getopt::Long::Descriptive>-based ones.
_
schema => 'bool',
},
);
sub _all_exec_in_PATH {
my @res;
for my $dir (split /:/, $ENV{PATH}) {
opendir my($dh), $dir or next;
for my $f (readdir $dh) {
next if $f eq '.' || $f eq '..';
next if $f =~ /~\z/; # skip backup files
next unless ((-f "$dir/$f") && (-x _));
push @res, "$dir/$f";
}
}
\@res;
}
sub _set_args_defaults {
my $args = shift;
if (!$args->{shell}) {
require Shell::Guess;
my $sh = Shell::Guess->running_shell;
my $n = $sh->{name};
$n = "zsh" if $n eq 'z';
$n = "tcsh" if $n eq 'c';
$n = "bash" if $n eq 'bourne'; # under make
$args->{shell} = $n;
}
unless (grep { $_ eq $args->{shell} } @supported_shells) {
return [412, "Unsupported shell '$args->{shell}'"];
}
$args->{global} //= ($> ? 0:1);
$args->{bash_global_dir} //= ['/etc/bash/completions'];
$args->{bash_per_user_dir} //= ["$ENV{HOME}/.config/bash/completions"];
$args->{fish_global_dir} //= ['/etc/fish/completions'];
$args->{fish_per_user_dir} //= ["$ENV{HOME}/.config/fish/completions"];
$args->{tcsh_global_dir} //= ['/etc/tcsh/completions'];
$args->{tcsh_per_user_dir} //= ["$ENV{HOME}/.config/tcsh/completions"];
$args->{zsh_global_dir} //= ['/usr/local/share/zsh/site-functions'];
$args->{zsh_per_user_dir} //= ["$ENV{HOME}/.config/zsh/completions"];
$args->{helper_global_dir} //= '/etc/shcompgen/helpers';
$args->{helper_per_user_dir} //= "$ENV{HOME}/.config/shcompgen/helpers";
[200];
}
sub _tcsh_init_script_path {
my %args = @_;
if ($args{global}) {
return "/etc/shcompgen.tcshrc";
} else {
return "$ENV{HOME}/.config/shcompgen.tcshrc";
}
}
sub _gen_tcsh_init_script {
my %args = @_;
my $dirs = $args{global} ?
$args{tcsh_global_dir} : $args{tcsh_per_user_dir};
my @defs;
for my $dir (@$dirs) {
next unless -d $dir;
for my $file (glob "$dir/*") {
open my $fh, "<", $file or do {
warn "Can't open '$file': $!, skipped\n";
next;
};
my $line = <$fh>;
( run in 2.966 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )