line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Complete::Fish; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2020-01-29'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.060'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
53520
|
use 5.010001; |
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
11
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
334
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
format_completion |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
require Complete::Bash; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our %SPEC; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$SPEC{':package'} = { |
21
|
|
|
|
|
|
|
v => 1.1, |
22
|
|
|
|
|
|
|
summary => 'Completion module for fish shell', |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$SPEC{format_completion} = { |
26
|
|
|
|
|
|
|
v => 1.1, |
27
|
|
|
|
|
|
|
summary => 'Format completion for output (for shell)', |
28
|
|
|
|
|
|
|
description => <<'_', |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
fish accepts completion reply in the form of one entry per line to STDOUT. |
31
|
|
|
|
|
|
|
Description can be added to each entry, prefixed by tab character. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
_ |
34
|
|
|
|
|
|
|
args_as => 'array', |
35
|
|
|
|
|
|
|
args => { |
36
|
|
|
|
|
|
|
completion => { |
37
|
|
|
|
|
|
|
summary => 'Completion answer structure', |
38
|
|
|
|
|
|
|
description => <<'_', |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Either an array or hash, as described in `Complete`. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
_ |
43
|
|
|
|
|
|
|
schema=>['any*' => of => ['hash*', 'array*']], |
44
|
|
|
|
|
|
|
req=>1, |
45
|
|
|
|
|
|
|
pos=>0, |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
result => { |
49
|
|
|
|
|
|
|
summary => 'Formatted string (or array, if `as` key is set to `array`)', |
50
|
|
|
|
|
|
|
schema => ['any*' => of => ['str*', 'array*']], |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
result_naked => 1, |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
sub format_completion { |
55
|
2
|
|
|
2
|
1
|
3040
|
my $comp = shift; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
4
|
my $as; |
58
|
|
|
|
|
|
|
my $entries; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# we currently use Complete::Bash's rule because i haven't done a read up on |
61
|
|
|
|
|
|
|
# how exactly fish escaping rules are. |
62
|
2
|
50
|
|
|
|
5
|
if (ref $comp eq 'HASH') { |
63
|
0
|
|
0
|
|
|
0
|
$as = $comp->{as} // 'string'; |
64
|
0
|
|
|
|
|
0
|
$entries = Complete::Bash::format_completion({%$comp}, {as=>'array'}); |
65
|
|
|
|
|
|
|
} else { |
66
|
2
|
|
|
|
|
4
|
$as = 'string'; |
67
|
2
|
|
|
|
|
8
|
$entries = Complete::Bash::format_completion({words=>$comp}, {as=>'array'}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# insert description |
71
|
|
|
|
|
|
|
{ |
72
|
2
|
50
|
|
|
|
993
|
my $compary = ref($comp) eq 'HASH' ? $comp->{words} : $comp; |
|
2
|
|
|
|
|
6
|
|
73
|
2
|
|
|
|
|
7
|
for (my $i=0; $i<@$compary; $i++) { |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $desc = (ref($compary->[$i]) eq 'HASH' ? |
76
|
6
|
100
|
50
|
|
|
15
|
$compary->[$i]{description} : '' ) // ''; |
77
|
6
|
|
|
|
|
8
|
$desc =~ s/\R/ /g; |
78
|
6
|
|
|
|
|
13
|
$entries->[$i] .= "\t$desc"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# turn back to string if that's what the user wants |
83
|
2
|
50
|
|
|
|
6
|
if ($as eq 'string') { |
84
|
2
|
|
|
|
|
3
|
$entries = join("", map{"$_\n"} @$entries); |
|
6
|
|
|
|
|
12
|
|
85
|
|
|
|
|
|
|
} |
86
|
2
|
|
|
|
|
7
|
$entries; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
# ABSTRACT: Completion module for fish shell |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |