App-shcompgen

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


        - Use shell=bash when running under make (detected as bourne).

        - [Bugfix] init: didn't create completion scripts dir on fish.


0.20    2016-10-21  Released-By: PERLANCAR

        - [Enhancement] Add support for fish shell.

        - [Enhancement] Add subcommands (for utility/testing): guess-shell,
          detect-prog.

        - [doc] Remove note about 'init' and 'generate' being run the first time
          it's installed because it doesn't work usually because we detect shell
          as 'bourne' under make and bail.

        - generate: Add option --stdout.


0.19    2016-07-12  Released-By: PERLANCAR

README  view on Meta::CPAN

    Detect a program.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   prog* => *str*

    *   shell => *str*

        Override guessing and select shell manually.

    Returns an enveloped result (an array).

    First element ($status_code) is an integer containing HTTP-like status
    code (200 means OK, 4xx caller error, 5xx function error). Second
    element ($reason) is a string containing error message, or something
    like "OK" if status is 200. Third element ($payload) is the actual
    result, but usually not present when enveloped result is an error
    response ($status_code is not 2xx). Fourth element (%result_meta) is
    called result metadata and is optional, a hash that contains extra

README  view on Meta::CPAN


    *   replace => *bool*

        Replace existing script.

        The default behavior is to skip if an existing completion script
        exists.

    *   shell => *str*

        Override guessing and select shell manually.

    *   stdout => *bool*

        Output completion script to STDOUT.

    *   tcsh_global_dir => *array[str]* (default: ["/etc/tcsh/completions"])

        Directory to put completions scripts.

    *   tcsh_per_user_dir => *array[str]*

README  view on Meta::CPAN

    element ($reason) is a string containing error message, or something
    like "OK" if status is 200. Third element ($payload) is the actual
    result, but usually not present when enveloped result is an error
    response ($status_code is not 2xx). Fourth element (%result_meta) is
    called result metadata and is optional, a hash that contains extra
    information, much like how HTTP response headers provide additional
    metadata.

    Return value: (any)

  guess_shell
    Usage:

     guess_shell() -> [$status_code, $reason, $payload, \%result_meta]

    Guess running shell.

    This function is not exported.

    No arguments.

    Returns an enveloped result (an array).

    First element ($status_code) is an integer containing HTTP-like status

README  view on Meta::CPAN

        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.
        Perinci::CmdLine- (that does not have subcommands) or
        Getopt::Long::Descriptive-based ones.

    *   shell => *str*

        Override guessing and select shell manually.

    *   tcsh_global_dir => *array[str]* (default: ["/etc/tcsh/completions"])

        Directory to put completions scripts.

    *   tcsh_per_user_dir => *array[str]*

        Directory to put completions scripts.

    *   zsh_global_dir => *array[str]* (default:

README  view on Meta::CPAN

        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.
        Perinci::CmdLine- (that does not have subcommands) or
        Getopt::Long::Descriptive-based ones.

    *   shell => *str*

        Override guessing and select shell manually.

    *   tcsh_global_dir => *array[str]* (default: ["/etc/tcsh/completions"])

        Directory to put completions scripts.

    *   tcsh_per_user_dir => *array[str]*

        Directory to put completions scripts.

    *   zsh_global_dir => *array[str]* (default:

README  view on Meta::CPAN


    *   prog => *array[str]*

        Program(s) to remove completion script of.

        Can contain path (e.g. "../foo") or a plain word ("foo") in which
        case will be searched from PATH.

    *   shell => *str*

        Override guessing and select shell manually.

    *   tcsh_global_dir => *array[str]* (default: ["/etc/tcsh/completions"])

        Directory to put completions scripts.

    *   tcsh_per_user_dir => *array[str]*

        Directory to put completions scripts.

    *   zsh_global_dir => *array[str]* (default:

lib/App/shcompgen.pm  view on Meta::CPAN

        };
    } else {
        # or user might want to mention a program in PATH
        Complete::Program::complete_program(word=>$word);
    }
};

our @supported_shells = qw(bash fish zsh tcsh);
our %shell_arg = (
    shell => {
        summary => 'Override guessing and select shell manually',
        schema => ['str*', {in=>\@supported_shells}],
        tags => ['common'],
        cmdline_aliases => {
            fish => {summary=>"Shortcut for --shell=fish", is_flag=>1, code=>sub { $_[0]{shell} = "fish" }},
            zsh  => {summary=>"Shortcut for --shell=zsh" , is_flag=>1, code=>sub { $_[0]{shell} = "zsh"  }},
            tcsh => {summary=>"Shortcut for --shell=tcsh", is_flag=>1, code=>sub { $_[0]{shell} = "tcsh" }},
        },
    },
);
our %common_args = (

lib/App/shcompgen.pm  view on Meta::CPAN

            my $init_script_path = _tcsh_init_script_path(%args);
            my $init_script = _gen_tcsh_init_script(%args);
            log_debug("Re-writing init script %s ...", $init_script_path);
            write_text($init_script_path, $init_script);
        }
    }

    $envres->as_struct;
}

$SPEC{guess_shell} = {
    v => 1.1,
    summary => 'Guess running shell',
    args => {
    },
};
sub guess_shell {
    my %args = @_;

    my $setdef_res = _set_args_defaults(\%args);
    return $setdef_res unless $setdef_res->[0] == 200;

    [200, "OK", $args{shell}];
}

$SPEC{detect_prog} = {
    v => 1.1,

lib/App/shcompgen.pm  view on Meta::CPAN

This function is not exported.

Arguments ('*' denotes required arguments):

=over 4

=item * B<prog>* => I<str>

=item * B<shell> => I<str>

Override guessing and select shell manually.


=back

Returns an enveloped result (an array).

First element ($status_code) is an integer containing HTTP-like status code
(200 means OK, 4xx caller error, 5xx function error). Second element
($reason) is a string containing error message, or something like "OK" if status is
200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth

lib/App/shcompgen.pm  view on Meta::CPAN

enabled, however, such existing completion script will be removed.

=item * B<replace> => I<bool>

Replace existing script.

The default behavior is to skip if an existing completion script exists.

=item * B<shell> => I<str>

Override guessing and select shell manually.

=item * B<stdout> => I<bool>

Output completion script to STDOUT.

=item * B<tcsh_global_dir> => I<array[str]> (default: ["/etc/tcsh/completions"])

Directory to put completions scripts.

=item * B<tcsh_per_user_dir> => I<array[str]>

lib/App/shcompgen.pm  view on Meta::CPAN

(200 means OK, 4xx caller error, 5xx function error). Second element
($reason) is a string containing error message, or something like "OK" if status is
200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth
element (%result_meta) is called result metadata and is optional, a hash
that contains extra information, much like how HTTP response headers provide additional metadata.

Return value:  (any)



=head2 guess_shell

Usage:

 guess_shell() -> [$status_code, $reason, $payload, \%result_meta]

Guess running shell.

This function is not exported.

No arguments.

Returns an enveloped result (an array).

First element ($status_code) is an integer containing HTTP-like status code

lib/App/shcompgen.pm  view on Meta::CPAN


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. L<Perinci::CmdLine>-
(that does not have subcommands) or L<Getopt::Long::Descriptive>-based ones.

=item * B<shell> => I<str>

Override guessing and select shell manually.

=item * B<tcsh_global_dir> => I<array[str]> (default: ["/etc/tcsh/completions"])

Directory to put completions scripts.

=item * B<tcsh_per_user_dir> => I<array[str]>

Directory to put completions scripts.

=item * B<zsh_global_dir> => I<array[str]> (default: ["/usr/local/share/zsh/site-functions"])

lib/App/shcompgen.pm  view on Meta::CPAN


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. L<Perinci::CmdLine>-
(that does not have subcommands) or L<Getopt::Long::Descriptive>-based ones.

=item * B<shell> => I<str>

Override guessing and select shell manually.

=item * B<tcsh_global_dir> => I<array[str]> (default: ["/etc/tcsh/completions"])

Directory to put completions scripts.

=item * B<tcsh_per_user_dir> => I<array[str]>

Directory to put completions scripts.

=item * B<zsh_global_dir> => I<array[str]> (default: ["/usr/local/share/zsh/site-functions"])

lib/App/shcompgen.pm  view on Meta::CPAN


=item * B<prog> => I<array[str]>

Program(s) to remove completion script of.

Can contain path (e.g. C<../foo>) or a plain word (C<foo>) in which case will be
searched from PATH.

=item * B<shell> => I<str>

Override guessing and select shell manually.

=item * B<tcsh_global_dir> => I<array[str]> (default: ["/etc/tcsh/completions"])

Directory to put completions scripts.

=item * B<tcsh_per_user_dir> => I<array[str]>

Directory to put completions scripts.

=item * B<zsh_global_dir> => I<array[str]> (default: ["/usr/local/share/zsh/site-functions"])

script/shcompgen  view on Meta::CPAN

my $urlprefix = '/App/shcompgen/';
Perinci::CmdLine::Any->new(
    url => $urlprefix,
    log => $ENV{LOG} // 1,
    subcommands => {
        init     => {url=>"${urlprefix}init"},
        generate => {url=>"${urlprefix}generate"},
        list     => {url=>"${urlprefix}list"},
        remove   => {url=>"${urlprefix}remove"},

        'guess-shell' => {url=>"${urlprefix}guess_shell", summary => "(Utility) detect a program", tags=>["category:utility"]},
        'detect-prog' => {url=>"${urlprefix}detect_prog", summary => "(Utility) Guess running shell", tags=>["category:utility"]},
    },
)->run;

# ABSTRACT: Generate shell completion scripts
# PODNAME: shcompgen

__END__

=pod

script/shcompgen  view on Meta::CPAN

=head1 SUBCOMMANDS

=head2 B<detect-prog>

(Utility) Guess running shell.

=head2 B<generate>

Generate shell completion scripts for detectable programs.

=head2 B<guess-shell>

(Utility) detect a program.

=head2 B<init>

Initialize shcompgen.

This subcommand creates the completion directories and initialization shell
script, as well as run C<generate>.

script/shcompgen  view on Meta::CPAN

This option will pipe the output to a specified pager program. If pager program
is not specified, a suitable default e.g. C<less> is chosen.


=item B<--quiet>

Shortcut for --log-level=error.

=item B<--shell>=I<s>

Override guessing and select shell manually.

Valid values:

 ["bash","fish","zsh","tcsh"]

=item B<--subcommands>

List available subcommands.

=item B<--tcsh>

script/shcompgen  view on Meta::CPAN

 prog (see --prog)

=head2 Configuration for subcommand generate

 per_option (see --per-option)
 prog (see --prog)
 remove (see --remove)
 replace (see --replace)
 stdout (see --stdout)

=head2 Configuration for subcommand guess-shell


=head2 Configuration for subcommand init

 per_option (see --per-option)

=head2 Configuration for subcommand list

 detail (see --detail)
 per_option (see --per-option)



( run in 0.559 second using v1.01-cache-2.11-cpan-748bfb374f4 )