Complete-Bash

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


0.327   2019-07-02  Released-By: PERLANCAR; Urgency: medium

	- [removed] format_completion(): Remove drawing summary lines every N
	  rows, because bash sorting will mess it up, and I think it looks ugly
	  anyway.

	- format_completion(): No longer sort entries.

	- format_completion(): Close fzf process' input so fzf does not show
          rotating cursor.


0.326   2019-07-02  Released-By: PERLANCAR; Urgency: medium

	- Implement another feature stolen from Ingy's complete-shell: use
	  fzf for filters.


0.325   2019-06-28  Released-By: PERLANCAR; Urgency: low

Changes  view on Meta::CPAN

0.23    2015-12-30  Released-By: PERLANCAR

	- To prevent unnecessary breakages, make the previous change
	  (truncating current word) into a non-default behavior, activated
	  by passing truncate_current_word=>1 option to parse_cmdline().


0.22    2015-12-30  Released-By: PERLANCAR

	- [ux][experimental] Truncate current word to the position of
	  cursor, so completing something like (^ marks the position of
	  cursor) --vers^oo is regarded as --vers instead of --versoo, thus
	  more convenient.


0.21    2015-09-09  Released-By: PERLANCAR

	- No functional changes.

	- [dist] Move spec prereqs from RuntimeRequires to
	  DevelopRecommends to reduce deps but still allow indicating spec
	  requirement.

README  view on Meta::CPAN

    Bash allows completion to come from various sources. The simplest is
    from a list of words ("-W"):

     % complete -W "one two three four" somecmd
     % somecmd t<Tab>
     two  three

    Another source is from a bash function ("-F"). The function will receive
    input in two variables: "COMP_WORDS" (array, command-line chopped into
    words) and "COMP_CWORD" (integer, index to the array of words indicating
    the cursor position). It must set an array variable "COMPREPLY" that
    contains the list of possible completion:

     % _foo()
     {
       local cur
       COMPREPLY=()
       cur=${COMP_WORDS[COMP_CWORD]}
       COMPREPLY=($( compgen -W '--help --verbose --version' -- $cur ) )
     }
     % complete -F _foo foo
     % foo <Tab>
     --help  --verbose  --version

    And yet another source is an external command ("-C") including, from a
    Perl script. The command receives two environment variables: "COMP_LINE"
    (string, raw command-line) and "COMP_POINT" (integer, cursor location).
    Program must split "COMP_LINE" into words, find the word to be
    completed, complete that, and return the list of words one per-line to
    STDOUT. An example:

     % cat foo-complete
     #!/usr/bin/perl
     use Complete::Bash qw(parse_cmdline format_completion);
     use Complete::Util qw(complete_array_elem);
     my ($words, $cword) = @{ parse_cmdline() };
     my $res = complete_array_elem(array=>[qw/--help --verbose --version/], word=>$words->[$cword]);

README  view on Meta::CPAN


        Command-line, defaults to COMP_LINE environment.

    *   $opts => *hash*

        Options.

        Optional. Known options:

        *   "truncate_current_word" (bool). If set to 1, will truncate
            current word to the position of cursor, for example ("^" marks
            the position of cursor): "--vers^oo" to "--vers" instead of
            "--versoo". This is more convenient when doing tab completion.

    *   $point => *int*

        Point/position to complete in command-line, defaults to COMP_POINT.

    Return value: (array)

    Return a 2-element array: "[$words, $cword]". $words is array of str,
    equivalent to "COMP_WORDS" provided by bash to shell functions. $cword

README  view on Meta::CPAN

    element from $words and reduce $cword by 1.

  point
    Usage:

     point($cmdline, $marker) -> any

    Return line with point marked by a marker.

    This is a utility function useful for testing/debugging.
    "parse_cmdline()" expects a command-line and a cursor position ($line,
    $point). This routine expects $line with a marker character (by default
    it's the caret, "^") and return ($line, $point) to feed to
    "parse_cmdline()".

    Example:

     point("^foo") # => ("foo", 0)
     point("fo^o") # => ("foo", 2)

    This function is not exported by default, but exportable.

lib/Complete/Bash.pm  view on Meta::CPAN

    $word =~ s/\\(.)/$1/g;
    $word;
}

$SPEC{point} = {
    v => 1.1,
    summary => 'Return line with point marked by a marker',
    description => <<'_',

This is a utility function useful for testing/debugging. `parse_cmdline()`
expects a command-line and a cursor position (`$line`, `$point`). This routine
expects `$line` with a marker character (by default it's the caret, `^`) and
return (`$line`, `$point`) to feed to `parse_cmdline()`.

Example:

    point("^foo") # => ("foo", 0)
    point("fo^o") # => ("foo", 2)

_
    args_as => 'array',

lib/Complete/Bash.pm  view on Meta::CPAN

            pos => 1,
        },
        opts => {
            summary => 'Options',
            schema => 'hash*',
            description => <<'_',

Optional. Known options:

* `truncate_current_word` (bool). If set to 1, will truncate current word to the
  position of cursor, for example (`^` marks the position of cursor):
  `--vers^oo` to `--vers` instead of `--versoo`. This is more convenient when
  doing tab completion.

_
            schema => 'hash*',
            pos => 2,
        },
    },
    result => {
        schema => ['array*', len=>2],

lib/Complete/Bash.pm  view on Meta::CPAN

            last;
        }
    }

  WORKAROUND_WITH_WORDBREAKS:
    # this is a workaround. since bash breaks words using characters in
    # $COMP_WORDBREAKS, which by default is "'@><=;|&(: this presents a problem
    # we often encounter: if we want to provide with a list of strings
    # containing say ':', most often Perl modules/packages, if user types e.g.
    # "Text::AN" and we provide completion ["Text::ANSI"] then bash will change
    # the word at cursor to become "Text::Text::ANSI" since it sees the current
    # word as "AN" and not "Text::AN". the workaround is to chop /^Text::/ from
    # completion answers. btw, we actually chop /^text::/i to handle
    # case-insensitive matching, although this does not have the ability to
    # replace the current word (e.g. if we type 'text::an' then bash can only
    # replace the current word 'an' with 'ANSI).
    {
        last unless $opts->{workaround_with_wordbreaks} // 1;
        last unless defined $opts->{word};

        if ($opts->{word} =~ s/(.+[\@><=;|&\(:])//) {

lib/Complete/Bash.pm  view on Meta::CPAN


Bash allows completion to come from various sources. The simplest is from a list
of words (C<-W>):

 % complete -W "one two three four" somecmd
 % somecmd t<Tab>
 two  three

Another source is from a bash function (C<-F>). The function will receive input
in two variables: C<COMP_WORDS> (array, command-line chopped into words) and
C<COMP_CWORD> (integer, index to the array of words indicating the cursor
position). It must set an array variable C<COMPREPLY> that contains the list of
possible completion:

 % _foo()
 {
   local cur
   COMPREPLY=()
   cur=${COMP_WORDS[COMP_CWORD]}
   COMPREPLY=($( compgen -W '--help --verbose --version' -- $cur ) )
 }
 % complete -F _foo foo
 % foo <Tab>
 --help  --verbose  --version

And yet another source is an external command (C<-C>) including, from a Perl
script. The command receives two environment variables: C<COMP_LINE> (string,
raw command-line) and C<COMP_POINT> (integer, cursor location). Program must
split C<COMP_LINE> into words, find the word to be completed, complete that, and
return the list of words one per-line to STDOUT. An example:

 % cat foo-complete
 #!/usr/bin/perl
 use Complete::Bash qw(parse_cmdline format_completion);
 use Complete::Util qw(complete_array_elem);
 my ($words, $cword) = @{ parse_cmdline() };
 my $res = complete_array_elem(array=>[qw/--help --verbose --version/], word=>$words->[$cword]);
 print format_completion($res);

lib/Complete/Bash.pm  view on Meta::CPAN


=item * B<$opts> => I<hash>

Options.

Optional. Known options:

=over

=item * C<truncate_current_word> (bool). If set to 1, will truncate current word to the
position of cursor, for example (C<^> marks the position of cursor):
C<--vers^oo> to C<--vers> instead of C<--versoo>. This is more convenient when
doing tab completion.

=back

=item * B<$point> => I<int>

PointE<sol>position to complete in command-line, defaults to COMP_POINT.


lib/Complete/Bash.pm  view on Meta::CPAN


=head2 point

Usage:

 point($cmdline, $marker) -> any

Return line with point marked by a marker.

This is a utility function useful for testing/debugging. C<parse_cmdline()>
expects a command-line and a cursor position (C<$line>, C<$point>). This routine
expects C<$line> with a marker character (by default it's the caret, C<^>) and
return (C<$line>, C<$point>) to feed to C<parse_cmdline()>.

Example:

 point("^foo") # => ("foo", 0)
 point("fo^o") # => ("foo", 2)

This function is not exported by default, but exportable.



( run in 0.333 second using v1.01-cache-2.11-cpan-4d50c553e7e )