App-Rakubrew
view release on metacpan or search on metacpan
lib/App/Rakubrew/Shell/PowerShell.pm view on Meta::CPAN
}
# TODO: \$PSVersionTable.PSVersion is only available from PowerShell 2.0 onward. Either accept that this fails on PS 1 or find a way to guard against that.
if (\$PSVersionTable.PSVersion.Major -ge 5) {
Register-ArgumentCompleter -Native -CommandName $brew_name -ScriptBlock {
param(\$commandName, \$argumentString, \$position)
\$completions = . "$brew_exec" internal_shell_hook PowerShell completions "\$position" "\$argumentString" | Out-String
\$completions = \$completions.trim('\n').Split(' ')
\$completions | ForEach-Object {
[System.Management.Automation.CompletionResult]::new(\$_, \$_, 'ParameterValue', \$_)
}
}
}
EOT
}
sub post_call_eval {
my $self = shift;
$self->print_shellmod_code(@_);
}
sub get_path_setter_code {
my $self = shift;
my $path = shift;
return "\$Env:PATH = \"$path\"";
}
sub get_shell_setter_code {
my $self = shift;
my $version = shift;
return "Set-Variable -Name $env_var -Value \"$version\" -Scope Global";
}
sub get_shell_unsetter_code {
my $self = shift;
return "Remove-Variable -Name $env_var -Scope Global";
}
sub completions {
my $self = shift;
my $position = shift;
my $argumentString = join ' ', @_;
# Check if the cursor is starting a new word (preceding space).
my $newWord = $position > length($argumentString) ? 1
: substr($argumentString, $position - 1, $position) eq ' ' ? 1
: 0;
# Cut off everything after cursor position.
$argumentString = substr($argumentString, 0, $position);
# Chop off trailing space.
$argumentString = chop($argumentString) if substr($argumentString, 0, length($argumentString) - 1) eq ' ';
# Remove command name and trailing space from arguments.
$argumentString =~ s/(^|.*\W)$brew_name(\.bat|\.exe)? ?//;
my @words = split ' ', $argumentString;
my $index = @words - 1 + ($newWord ? 1 : 0);
my @completions = $self->get_completions($index, @words);
say join(' ', @completions);
}
1;
( run in 0.352 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )