Mending Broken Windows #2

Editor, no Remove-Alias before PowrShell Core.
IValidateSetValuesGenerator missing before PowerShell Core
This commit is contained in:
lksz 2020-09-30 00:14:51 -04:00
parent 586f187346
commit 607fff132f
4 changed files with 21 additions and 6 deletions

View File

@ -4,9 +4,13 @@
[string[]]$Path
)
$local:editor = '/bin/nvim'
if( (Test-Path env:EDITOR) -and (Test-Path $env:EDITOR) ) {
$editor = $env:EDITOR;
$local:editors = $env:EDITOR,'nvim','code'
$local:editor = $null
foreach( $local:testEditor in $editors ) {
if( Get-Command -Type Application $testEditor -ErrorAction SilentlyContinue ) {
$editor = $testEditor
break;
}
}
if( $editor -match 'vim?$' ) {
@ -17,6 +21,12 @@ if( $sudo ) {
$editor = "/usr/bin/env sudo $editor"
}
if( $editor -match 'code(\.exe)?$' ) {
if( -not (Get-Process -Name 'code' -ErrorAction SilentlyContinue) ) {
& $editor
}
}
$local:arguments = $Path -join "' '"
if( $Path ) { $arguments = "'$arguments'" }

View File

@ -23,7 +23,12 @@ $oldAliases = Get-Alias -Scope $MyAliasScope |
if( $oldAliases -and $IsVerbose ) {
Write-Verbose "Removing: $($oldAliases.Name -join ', ')"
}
$oldAliases | Remove-Alias -Scope $MyAliasScope
if( Get-Command Remove-Alias -ErrorAction SilentlyContinue ) {
$oldAliases | Remove-Alias -Scope $MyAliasScope
} else {
$oldAliases | ForEach-Object { Remove-Item "Alias:$($_.Name)" }
}
Get-ChildItem (Join-Path $MyPSScriptRoot '*.ps1') |
ForEach-Object {
Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope

View File

@ -1,4 +1,4 @@
class FunctionName: System.Management.Automation.IValidateSetValuesGenerator {
class FunctionName { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = Get-Command -Type Function | Select-Object -ExpandProperty Name
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );

View File

@ -1,4 +1,4 @@
class MyScript : System.Management.Automation.IValidateSetValuesGenerator {
class MyScript { #: System.Management.Automation.IValidateSetValuesGenerator {
static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = $(
Get-ChildItem $global:MyPSScriptRoot -Filter '*.ps1' -Recurse |