| 1 | package Complete::Tcsh; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | our $DATE = '2019-12-20'; # DATE | |||||||||||||||||||
| 4 | 1 | our $VERSION = '0.030'; # VERSION | |||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use 5.010001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | require Exporter; | |||||||||||||||||||
| 11 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 12 | 1 | our @EXPORT_OK = qw( | |||||||||||||||||||
| 13 | parse_cmdline | ||||||||||||||||||||
| 14 | format_completion | ||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 1 | require Complete::Bash; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | our %SPEC; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | $SPEC{':package'} = { | |||||||||||||||||||
| 22 | v => 1.1, | ||||||||||||||||||||
| 23 | summary => 'Completion module for tcsh shell', | ||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | $SPEC{parse_cmdline} = { | ||||||||||||||||||||
| 27 | 1 | v => 1.1, | |||||||||||||||||||
| 28 | summary => 'Parse shell command-line for processing by completion routines', | ||||||||||||||||||||
| 29 | description => <<'_', | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | This function converts COMMAND_LINE (str) given by tcsh to become something like | ||||||||||||||||||||
| 32 | COMP_WORDS (array) and COMP_CWORD (int), like what bash supplies to shell | ||||||||||||||||||||
| 33 | functions. Currently implemented using `Complete::Bash`'s `parse_cmdline`. | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | _ | ||||||||||||||||||||
| 36 | args_as => 'array', | ||||||||||||||||||||
| 37 | args => { | ||||||||||||||||||||
| 38 | cmdline => { | ||||||||||||||||||||
| 39 | summary => 'Command-line, defaults to COMMAND_LINE environment', | ||||||||||||||||||||
| 40 | schema => 'str*', | ||||||||||||||||||||
| 41 | pos => 0, | ||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||
| 43 | }, | ||||||||||||||||||||
| 44 | result => { | ||||||||||||||||||||
| 45 | schema => ['array*', len=>2], | ||||||||||||||||||||
| 46 | description => <<'_', | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | Return a 2-element array: `[$words, $cword]`. `$words` is array of str, | ||||||||||||||||||||
| 49 | equivalent to `COMP_WORDS` provided by bash to shell functions. `$cword` is an | ||||||||||||||||||||
| 50 | integer, equivalent to `COMP_CWORD` provided by bash to shell functions. The | ||||||||||||||||||||
| 51 | word to be completed is at `$words->[$cword]`. | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | Note that COMP_LINE includes the command name. If you want the command-line | ||||||||||||||||||||
| 54 | arguments only (like in `@ARGV`), you need to strip the first element from | ||||||||||||||||||||
| 55 | `$words` and reduce `$cword` by 1. | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | _ | ||||||||||||||||||||
| 58 | }, | ||||||||||||||||||||
| 59 | result_naked => 1, | ||||||||||||||||||||
| 60 | }; | ||||||||||||||||||||
| 61 | 0 | ▶ | sub parse_cmdline { | ||||||||||||||||||
|
Subroutine
parse_cmdline: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 62 | 0 | my ($line) = @_; | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ▶ | $line //= $ENV{COMMAND_LINE}; | ||||||||||||||||||
|
Condition0%0/3
$line //= $ENV{"COMMAND_LINE"}
MC/DC0%0/2
$line //= $ENV{"COMMAND_LINE"}
$line
$ENV{"COMMAND_LINE"}
Truth table0%0/3
A //= B
A= $lineB= $ENV{"COMMAND_LINE"}
| |||||||||||||||||||||
| 65 | 0 | Complete::Bash::parse_cmdline($line, length($line)); | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | $SPEC{format_completion} = { | ||||||||||||||||||||
| 69 | 1 | v => 1.1, | |||||||||||||||||||
| 70 | summary => 'Format completion for output (for shell)', | ||||||||||||||||||||
| 71 | description => <<'_', | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | tcsh accepts completion reply in the form of one entry per line to STDOUT. | ||||||||||||||||||||
| 74 | Currently the formatting is done using `Complete::Bash`'s `format_completion` | ||||||||||||||||||||
| 75 | because escaping rule and so on are not yet well defined in tcsh. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | _ | ||||||||||||||||||||
| 78 | args_as => 'array', | ||||||||||||||||||||
| 79 | args => { | ||||||||||||||||||||
| 80 | completion => { | ||||||||||||||||||||
| 81 | summary => 'Completion answer structure', | ||||||||||||||||||||
| 82 | description => <<'_', | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | Either an array or hash, as described in `Complete`. | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | _ | ||||||||||||||||||||
| 87 | schema=>['any*' => of => ['hash*', 'array*']], | ||||||||||||||||||||
| 88 | req=>1, | ||||||||||||||||||||
| 89 | pos=>0, | ||||||||||||||||||||
| 90 | }, | ||||||||||||||||||||
| 91 | }, | ||||||||||||||||||||
| 92 | result => { | ||||||||||||||||||||
| 93 | summary => 'Formatted string (or array, if `as` is set to `array`)', | ||||||||||||||||||||
| 94 | schema => ['any*' => of => ['str*', 'array*']], | ||||||||||||||||||||
| 95 | }, | ||||||||||||||||||||
| 96 | result_naked => 1, | ||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||
| 98 | 0 | ▶ | sub format_completion { | ||||||||||||||||||
|
Subroutine
format_completion: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 99 | 0 | Complete::Bash::format_completion(@_); | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 1 | 1; | |||||||||||||||||||
| 103 | # ABSTRACT: Completion module for tcsh shell | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||