line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Complete::Env; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-10-18'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.39'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
61545
|
use 5.010001; |
|
3
|
|
|
|
|
10
|
|
7
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
68
|
|
8
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
96
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
1696
|
use Complete::Common qw(:all); |
|
3
|
|
|
|
|
1119
|
|
|
3
|
|
|
|
|
1873
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
15
|
|
|
|
|
|
|
complete_env |
16
|
|
|
|
|
|
|
complete_env_elem |
17
|
|
|
|
|
|
|
complete_path_env_elem |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our %SPEC; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$SPEC{':package'} = { |
23
|
|
|
|
|
|
|
v => 1.1, |
24
|
|
|
|
|
|
|
summary => 'Completion routines related to environment variables', |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$SPEC{complete_env} = { |
28
|
|
|
|
|
|
|
v => 1.1, |
29
|
|
|
|
|
|
|
summary => 'Complete from environment variables', |
30
|
|
|
|
|
|
|
description => <<'_', |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
On Windows, environment variable names are all converted to uppercase. You can |
33
|
|
|
|
|
|
|
use case-insensitive option (`ci`) to match against original casing. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
_ |
36
|
|
|
|
|
|
|
args => { |
37
|
|
|
|
|
|
|
word => { schema=>[str=>{default=>''}], pos=>0, req=>1 }, |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
result_naked => 1, |
40
|
|
|
|
|
|
|
result => { |
41
|
|
|
|
|
|
|
schema => 'array', |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
sub complete_env { |
45
|
1
|
|
|
1
|
1
|
631
|
require Complete::Util; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
3193
|
my %args = @_; |
48
|
1
|
|
50
|
|
|
5
|
my $word = $args{word} // ""; |
49
|
1
|
50
|
|
|
|
4
|
if ($word =~ /^\$/) { |
50
|
|
|
|
|
|
|
Complete::Util::complete_array_elem( |
51
|
0
|
|
|
|
|
0
|
word=>$word, array=>[map {"\$$_"} keys %ENV], |
|
0
|
|
|
|
|
0
|
|
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} else { |
54
|
1
|
|
|
|
|
6
|
Complete::Util::complete_array_elem( |
55
|
|
|
|
|
|
|
word=>$word, array=>[keys %ENV], |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$SPEC{complete_env_elem} = { |
61
|
|
|
|
|
|
|
v => 1.1, |
62
|
|
|
|
|
|
|
summary => 'Complete from elements of an environment variable', |
63
|
|
|
|
|
|
|
description => <<'_', |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
An environment variable like PATH contains colon- (or, on Windows, semicolon-) |
66
|
|
|
|
|
|
|
separated elements. This routine complete from the elements of such variable. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
_ |
69
|
|
|
|
|
|
|
args => { |
70
|
|
|
|
|
|
|
word => { schema=>[str=>{default=>''}], pos=>0, req=>1 }, |
71
|
|
|
|
|
|
|
env => { |
72
|
|
|
|
|
|
|
summary => 'Name of environment variable to use', |
73
|
|
|
|
|
|
|
schema => 'str*', |
74
|
|
|
|
|
|
|
req => 1, |
75
|
|
|
|
|
|
|
pos => 1, |
76
|
|
|
|
|
|
|
}, |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
result_naked => 1, |
79
|
|
|
|
|
|
|
result => { |
80
|
|
|
|
|
|
|
schema => 'array', |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
sub complete_env_elem { |
84
|
2
|
|
|
2
|
1
|
1449
|
require Complete::Util; |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
8480
|
my %args = @_; |
87
|
2
|
|
50
|
|
|
13
|
my $word = $args{word} // ""; |
88
|
2
|
|
|
|
|
5
|
my $env = $args{env}; |
89
|
2
|
|
|
|
|
3
|
my @elems; |
90
|
2
|
50
|
|
|
|
12
|
if ($^O eq 'MSWin32') { |
91
|
0
|
|
0
|
|
|
0
|
@elems = split /;/, ($ENV{$env} // ''); |
92
|
|
|
|
|
|
|
} else { |
93
|
2
|
|
50
|
|
|
14
|
@elems = split /:/, ($ENV{$env} // ''); |
94
|
|
|
|
|
|
|
} |
95
|
2
|
|
|
|
|
11
|
Complete::Util::complete_array_elem( |
96
|
|
|
|
|
|
|
word=>$word, array=>\@elems, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$SPEC{complete_path_env_elem} = { |
101
|
|
|
|
|
|
|
v => 1.1, |
102
|
|
|
|
|
|
|
summary => 'Complete from elements of PATH environment variable', |
103
|
|
|
|
|
|
|
description => <<'_', |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
PATH environment variable contains colon- (or, on Windows, semicolon-) separated |
106
|
|
|
|
|
|
|
elements. This routine complete from those elements. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
_ |
109
|
|
|
|
|
|
|
args => { |
110
|
|
|
|
|
|
|
word => { schema=>[str=>{default=>''}], pos=>0, req=>1 }, |
111
|
|
|
|
|
|
|
}, |
112
|
|
|
|
|
|
|
result_naked => 1, |
113
|
|
|
|
|
|
|
result => { |
114
|
|
|
|
|
|
|
schema => 'array', |
115
|
|
|
|
|
|
|
}, |
116
|
|
|
|
|
|
|
}; |
117
|
|
|
|
|
|
|
sub complete_path_env_elem { |
118
|
1
|
|
|
1
|
1
|
30
|
my %args = @_; |
119
|
1
|
|
|
|
|
5
|
complete_env_elem(word => $args{word}, env => 'PATH'); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
# ABSTRACT: Completion routines related to environment variables |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |