Complete::Bash::History - Parse command-line for options and arguments, more or less like Getopt::Long
This document describes version 0.060 of Complete::Bash::History (from Perl distribution Complete-Bash-History), released on 2020-01-29.
complete_cmdline_from_hist(%args) -> any
Complete command line from recent entries in bash history.
This routine will search your bash history file (recent first a.k.a. backward) for entries for the same command, and complete option with the same name or argument in the same position. For example, if you have history like this:
cmd1 --opt1 val arg1 arg2
cmd1 --opt1 valb arg1b arg2b arg3b
Then if you do:
complete_cmdline_from_hist(comp_line=>'cmd1 --bar --opt1 ', comp_point=>18);
then it means the routine will search for values for option --opt1 and will return:
Or if you do:
complete_cmdline_from_hist(comp_line=>'cmd1 baz ', comp_point=>9);
then it means the routine will search for second argument (argv) and will return:
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
cmdline => str
Command line, defaults to COMP_LINE.
max_hist_lines => int (default: 3000)
Stop searching after this amount of history lines.
-1 means unlimited (search all lines in the file).
Timestamp comments are not counted.
max_result => int (default: 100)
Stop after finding this number of distinct results.
-1 means unlimited.
path => str
Path to `.bash_history` file.
Defaults to ~/.bash_history.
If file does not exist or unreadable, will return empty completion answer.
point => int
Command line, defaults to COMP_POINT.
Return value: (any)
parse_options(%args) -> [status, msg, payload, meta]
Parse command-line for options and arguments, more or less like Getopt::Long.
Parse command-line into words using Complete::Bash's parse_cmdline() then separate options and arguments. Since this routine does not accept Getopt::Long (this routine is meant to be a generic option parsing of command-lines), it uses a few simple rules to server the common cases:
After --, the rest of the words are arguments (just like Getopt::Long).
If we get something like -abc (a single dash followed by several letters) it is assumed to be a bundle of short options.
If we get something like -MData::Dump (a single dash, followed by a letter, followed by some letters and non-letters/numbers) it is assumed to be an option (-M) followed by a value.
If we get something like --foo it is a long option. If the next word is an option (starts with a -) then it is assumed that this option does not have argument. Otherwise, the next word is assumed to be this option's value.
Otherwise, it is an argument (that is, permute is assumed).
This function is not exported.
Command-line, defaults to COMP_LINE environment.
cword => array[str]
Alternative to passing `cmdline` and `point`.
If you already did a parse_cmdline(), you can pass the cword result (the second element) here to avoid calling parse_cmdline() twice.
Point/position to complete in command-line, defaults to COMP_POINT.
words => array[str]
If you already did a parse_cmdline(), you can pass the words result (the first element) here to avoid calling parse_cmdline() twice.
Returns an enveloped result (an array).
First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (payload) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.
Return value: (hash)
Please visit the project's homepage at https://metacpan.org/release/Complete-Bash-History.
Source repository is at https://github.com/perlancar/perl-Complete-Bash-History.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Complete-Bash-History
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
This software is copyright (c) 2020, 2016, 2015, 2014 by firstname.lastname@example.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Complete::Bash::History, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.