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

View File

@ -23,7 +23,12 @@ $oldAliases = Get-Alias -Scope $MyAliasScope |
if( $oldAliases -and $IsVerbose ) { if( $oldAliases -and $IsVerbose ) {
Write-Verbose "Removing: $($oldAliases.Name -join ', ')" Write-Verbose "Removing: $($oldAliases.Name -join ', ')"
} }
if( Get-Command Remove-Alias -ErrorAction SilentlyContinue ) {
$oldAliases | Remove-Alias -Scope $MyAliasScope $oldAliases | Remove-Alias -Scope $MyAliasScope
} else {
$oldAliases | ForEach-Object { Remove-Item "Alias:$($_.Name)" }
}
Get-ChildItem (Join-Path $MyPSScriptRoot '*.ps1') | Get-ChildItem (Join-Path $MyPSScriptRoot '*.ps1') |
ForEach-Object { ForEach-Object {
Set-Alias $($_.BaseName) $_.FullName -Scope $MyAliasScope 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) { static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = Get-Command -Type Function | Select-Object -ExpandProperty Name $local:possibleValues = Get-Command -Type Function | Select-Object -ExpandProperty Name
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict ); 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) { static [string[]] _GetValidValues([string]$wordToComplete,[bool]$Strict) {
$local:possibleValues = $( $local:possibleValues = $(
Get-ChildItem $global:MyPSScriptRoot -Filter '*.ps1' -Recurse | Get-ChildItem $global:MyPSScriptRoot -Filter '*.ps1' -Recurse |