#!perl
our
$DATE
=
'2018-03-04'
;
our
$VERSION
=
'0.008'
;
use
5.010001;
complete_perl_available_to_install
complete_perl_installed_to_use
complete_perl_installed_name
complete_perl_alias
list_available_perls
list_available_perl_versions
list_installed_perls
list_installed_perl_versions
list_perl_libs
list_perl_aliases
)
;
die
"This script is for shell completion only\n"
unless
$ENV
{GETOPT_LONG_SUBCOMMAND_DUMP} ||
$ENV
{COMP_LINE} ||
$ENV
{COMMAND_LINE};
my
$noop
=
sub
{};
my
$specnoop
= {
handler
=>
$noop
};
GetOptions(
options
=> {
'quiet|q'
=>
$specnoop
,
'verbose|v'
=>
$specnoop
,
'version'
=>
$specnoop
,
},
subcommands
=> {
init
=> {
options
=> {
},
},
info
=> {
options
=> {
},
},
install
=> {
options
=> {
'force|f'
=>
$specnoop
,
'j=i'
=>
$specnoop
,
'notest|n'
=>
$specnoop
,
'switch'
=>
$specnoop
,
'as=s'
=>
$specnoop
,
'noman'
=>
$specnoop
,
'thread'
=>
$specnoop
,
'multi'
=>
$specnoop
,
'64int'
=>
$specnoop
,
'64all'
=>
$specnoop
,
'ld'
=>
$specnoop
,
'debug'
=>
$specnoop
,
'clang'
=>
$specnoop
,
'no-patchperl'
=>
$specnoop
,
'D=s'
=>
$specnoop
,
'U=s'
=>
$specnoop
,
'A=s'
=>
$specnoop
,
'destdir=s'
=>
$specnoop
,
'sitecustomize=s'
=>
$specnoop
,
},
},
uninstall
=> {
options
=> {
},
},
available
=> {
options
=> {
'all'
=>
$specnoop
,
},
},
lib
=> {
options
=> {
},
subcommands
=> {
list
=> {},
create
=> {},
delete
=> {},
},
},
alias
=> {
options
=> {
'f'
=>
$specnoop
,
},
subcommands
=> {
create
=> {},
rename
=> {},
delete
=> {},
},
},
'upgrade-perl'
=> {
options
=> {
},
},
list
=> {
options
=> {
},
},
use
=> {
options
=> {
},
},
off
=> {
options
=> {
},
},
switch
=> {
options
=> {
},
},
'switch-off'
=> {
options
=> {
},
},
exec
=> {
options
=> {
'with=s'
=>
$specnoop
,
},
},
'self-install'
=> {
options
=> {
},
},
'self-upgrade'
=> {
options
=> {
},
},
'install-patchperl'
=> {
options
=> {
},
},
'install-cpanm'
=> {
options
=> {
},
},
'install-multiple'
=> {
options
=> {
'both=s'
=>
$specnoop
,
'common-variations'
=>
$specnoop
,
'all-variations'
=>
$specnoop
,
'append=s'
=>
$specnoop
,
},
},
download
=> {
options
=> {
},
},
clean
=> {
options
=> {
},
},
version
=> {
options
=> {
},
},
help
=> {
options
=> {
},
},
'symlink-executables'
=> {
options
=> {
},
},
},
completion
=>
sub
{
my
%args
=
@_
;
log_trace(
"[_perlbrew] args=%s"
, \
%args
);
my
$subc
=
$args
{subcommand}->[0] //
''
;
my
$subc2
=
$args
{subcommand}->[1] //
''
;
my
$word
=
$args
{word};
my
$type
=
$args
{type};
my
$opt
=
$args
{opt};
if
(
$subc
eq
'info'
) {
if
(
$type
eq
'arg'
) {
return
Complete::Module::complete_module(
word
=>
$word
);
}
}
elsif
(
$subc
eq
'install'
||
$subc
eq
'install-multiple'
) {
if
(
$type
eq
'optval'
&&
$opt
=~ /\A(-j)\z/) {
return
complete_array_elem(
word
=>
$word
,
array
=> [1..10]);
}
elsif
(
$type
eq
'optval'
&&
$opt
=~ /\A(--sitecustomize)\z/) {
return
complete_file(
word
=>
$word
);
}
elsif
(
$type
eq
'optval'
&&
$opt
=~ /\A(--both)\z/) {
return
complete_array_elem(
word
=>
$word
,
array
=> [
qw/thread multi ld 64int 64all debug clang/
],
);
}
elsif
(
$type
eq
'arg'
) {
return
undef
if
$word
=~ m!\A\w+://!;
return
complete_file(
word
=>
$word
,
filter
=>
sub
{
return
0
unless
-f || (-d _);
if
(-f _) {
return
0
unless
/\.(tar\.gz|tar\.bz2|tar\.xz|tar)\z/i;
}
1;
},
)
if
$word
=~ m![/\\]|\.\.!;
return
complete_perl_available_to_install(
$word
);
}
}
elsif
(
$subc
eq
'uninstall'
) {
if
(
$type
eq
'arg'
) {
local
$Complete::Common::OPT_FUZZY
= 0;
return
complete_array_elem(
word
=>
$word
,
array
=> [list_installed_perls()],
);
}
}
elsif
(
$subc
eq
'use'
) {
if
(
$type
eq
'arg'
) {
return
complete_perl_installed_to_use(
$word
);
}
}
elsif
(
$subc
eq
'switch'
) {
if
(
$type
eq
'arg'
) {
return
complete_perl_installed_to_use(
$word
);
}
}
elsif
(
$subc
eq
'alias'
) {
if
(
$subc2
eq
'create'
) {
if
(
$type
eq
'arg'
&&
$args
{argpos} == 2) {
return
complete_perl_installed_name(
$word
);
}
}
elsif
(
$subc2
eq
'rename'
||
$subc2
eq
'delete'
) {
if
(
$type
eq
'arg'
&&
$args
{argpos} == 2) {
return
complete_perl_alias(
$word
);
}
}
}
elsif
(
$subc
eq
'exec'
) {
if
(
$type
eq
'optval'
&&
$opt
=~ /\A(--
with
)\z/) {
my
@items
=
split
','
,
$word
, -1;
$word
=
@items
?
pop
(
@items
) :
''
;
return
[
map
{
my
$s
=
join
(
","
,
@items
) . (
@items
?
','
:
''
) .
$_
;
$s
}
grep
{
my
$it
=
$_
; !(
grep
{
$_
eq
$it
}
@items
) }
@{ complete_perl_installed_name(
$word
) }
];
}
}
elsif
(
$subc
eq
'env'
) {
if
(
$type
eq
'arg'
) {
local
$Complete::Common::OPT_FUZZY
= 0;
return
complete_array_elem(
word
=>
$word
,
array
=> [list_installed_perls()],
);
}
}
elsif
(
$subc
eq
'symlink-executables'
) {
if
(
$type
eq
'arg'
) {
local
$Complete::Common::OPT_FUZZY
= 0;
return
complete_array_elem(
word
=>
$word
,
array
=> [list_installed_perls()],
);
}
}
elsif
(
$subc
eq
'lib'
) {
if
(
$subc2
eq
'delete'
) {
if
(
$type
eq
'arg'
&&
$args
{argpos} == 2) {
local
$Complete::Common::OPT_FUZZY
= 0;
return
complete_array_elem(
word
=>
$word
,
array
=> [
list_perl_libs(),
],
);
}
}
}
elsif
(
$subc
eq
'download'
) {
if
(
$type
eq
'arg'
) {
local
$Complete::Common::OPT_FUZZY
= 0;
return
complete_array_elem(
word
=>
$word
,
array
=> [
list_available_perls(),
],
);
}
}
undef
;
},
);