Improve performance of Package identification
Using -ListAvailable with Get-Command to ensure no module loading is attampeted while querying loaded commands. This improved performance when certain modules have not been loaded yet
This commit is contained in:
parent
499a86baa6
commit
22aa3ba435
|
@ -1,4 +1,4 @@
|
||||||
Get-Command Import-UnixCompleters -ErrorAction SilentlyContinue | ForEach-Object {
|
Get-Command -ListImported Import-UnixCompleters -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
Import-UnixCompleters
|
Import-UnixCompleters
|
||||||
Set-UnixCompleter -ShellType Bash
|
Set-UnixCompleter -ShellType Bash
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ if( $Package ) {
|
||||||
}
|
}
|
||||||
$local:ScriptPaths = @()
|
$local:ScriptPaths = @()
|
||||||
foreach( $local:p in $ImportFunction ) {
|
foreach( $local:p in $ImportFunction ) {
|
||||||
$local:f = Get-Command $p -Type Function
|
$local:f = Get-Command -ListImported $p -Type Function
|
||||||
if( $f ) {
|
if( $f ) {
|
||||||
$local:sp = Join-Path $EditRootPath "$p`.ps1"
|
$local:sp = Join-Path $EditRootPath "$p`.ps1"
|
||||||
if( $ForceImport -or -not (Test-Path $sp) ) {
|
if( $ForceImport -or -not (Test-Path $sp) ) {
|
||||||
|
@ -90,5 +90,5 @@ if( $sw.Elapsed.TotalSeconds -lt 1 ) {
|
||||||
$null = Read-Host "Waiting before refreshing. Press <Enter> when you're done editing ( don't forget to save ;) )..."
|
$null = Read-Host "Waiting before refreshing. Press <Enter> when you're done editing ( don't forget to save ;) )..."
|
||||||
}
|
}
|
||||||
|
|
||||||
Get-Command Reload-MyScripts -ErrorAction SilentlyContinue |
|
Get-Command -ListImported Reload-MyScripts -ErrorAction SilentlyContinue |
|
||||||
ForEach-Object { . $_.Definition }
|
ForEach-Object { . $_.Definition }
|
||||||
|
|
|
@ -17,7 +17,7 @@ end {
|
||||||
$local:editors = $env:EDITOR,'nvim','code'
|
$local:editors = $env:EDITOR,'nvim','code'
|
||||||
$local:editor = $null
|
$local:editor = $null
|
||||||
foreach( $local:testEditor in $editors ) {
|
foreach( $local:testEditor in $editors ) {
|
||||||
if( $(try{Get-Command -Type Application $testEditor -ErrorAction SilentlyContinue}catch{}) ) {
|
if( $(try{Get-Command -ListImported -Type Application $testEditor -ErrorAction SilentlyContinue}catch{}) ) {
|
||||||
$editor = $testEditor
|
$editor = $testEditor
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ function RemoveAlias {
|
||||||
param([string]$Name)
|
param([string]$Name)
|
||||||
$local:a = $Name | Where-Object { $_ } | Get-Alias -ErrorAction SilentlyContinue
|
$local:a = $Name | Where-Object { $_ } | Get-Alias -ErrorAction SilentlyContinue
|
||||||
if ( -not $a ) { return }
|
if ( -not $a ) { return }
|
||||||
if ( Get-Command Remove-Alias -ErrorAction SilentlyContinue ) {
|
if ( Get-Command -ListImported Remove-Alias -ErrorAction SilentlyContinue ) {
|
||||||
$a | Remove-Alias -Scope $MyAliasScope -ErrorAction SilentlyContinue
|
$a | Remove-Alias -Scope $MyAliasScope -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
if( -not (Get-Command Join-String -ErrorAction SilentlyContinue) ) {
|
if( -not (Get-Command -ListImported Join-String -ErrorAction SilentlyContinue) ) {
|
||||||
if( -not (Get-Module -ListAvailable -Name "string") ) {
|
if( -not (Get-Module -ListAvailable -Name "string") ) {
|
||||||
Write-Warning 'Join-String Command is missing, attempting to install stirng module'
|
Write-Warning 'Join-String Command is missing, attempting to install stirng module'
|
||||||
$local:moduleScope = "CurrentUser"
|
$local:moduleScope = "CurrentUser"
|
|
@ -15,7 +15,7 @@ if( Get-Module PowerShellCookbook ) {
|
||||||
Import-Module PowerShellCookbook -Cmdlet Add-ObjectCollector
|
Import-Module PowerShellCookbook -Cmdlet Add-ObjectCollector
|
||||||
}
|
}
|
||||||
#
|
#
|
||||||
. Get-Command Add-ObjectCollector -ErrorAction SilentlyContinue | ForEach-Object {
|
. Get-Command -ListImported Add-ObjectCollector -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
Add-ObjectCollector
|
Add-ObjectCollector
|
||||||
Get-Item function:/Add-ObjectCollector | Remove-Item
|
Get-Item function:/Add-ObjectCollector | Remove-Item
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
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 -ListImported -Type Function | Select-Object -ExpandProperty Name
|
||||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $possibleValues -Strict:$Strict );
|
||||||
}
|
}
|
||||||
static [String[]] _GetValidValues([string]$wordToComplete,[switch]$Strict) {
|
static [String[]] _GetValidValues([string]$wordToComplete,[switch]$Strict) {
|
||||||
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $(Get-Command -Type Function | Select-Object -ExpandProperty Name) -Strict:$Strict)
|
return $(Get-PossibleArguments -WordToComplete $wordToComplete -FullValueSet $(Get-Command -ListImported -Type Function | Select-Object -ExpandProperty Name) -Strict:$Strict)
|
||||||
# $local:possibleValues =
|
# $local:possibleValues =
|
||||||
# if( $wordToComplete ) {
|
# if( $wordToComplete ) {
|
||||||
# $possibleValues = $possibleValues | Where-Object { $_ -match $wordToComplete }
|
# $possibleValues = $possibleValues | Where-Object { $_ -match $wordToComplete }
|
||||||
|
|
|
@ -3,13 +3,13 @@ $global:IsOutputANSICompatible = (
|
||||||
) -or (
|
) -or (
|
||||||
($env:ConEmuANSI -eq 'ON') -and ($Host.Name -eq 'ConsoleHost' )
|
($env:ConEmuANSI -eq 'ON') -and ($Host.Name -eq 'ConsoleHost' )
|
||||||
)
|
)
|
||||||
Get-Command Set-PSReadLineKeyHandler -ErrorAction SilentlyContinue |
|
Get-Command -ListImported Set-PSReadLineKeyHandler -ErrorAction SilentlyContinue |
|
||||||
ForEach-Object { Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete }
|
ForEach-Object { Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete }
|
||||||
if( (Get-Command Set-PoshPrompt -ErrorAction SilentlyContinue) -and $IsOutputANSICompatible ) {
|
if( (Get-Command -ListImported Set-PoshPrompt -ErrorAction SilentlyContinue) -and $IsOutputANSICompatible ) {
|
||||||
$local:poshPrompt = Join-Path $HOME ".oh-my-posh.omp.json"
|
$local:poshPrompt = Join-Path $HOME ".oh-my-posh.omp.json"
|
||||||
if( -not (Test-Path $poshPrompt) ) { $poshPrompt = "slim" }
|
if( -not (Test-Path $poshPrompt) ) { $poshPrompt = "slim" }
|
||||||
Set-PoshPrompt -Theme $poshPrompt
|
Set-PoshPrompt -Theme $poshPrompt
|
||||||
} elseif( Get-Command Set-Theme -ErrorAction SilentlyContinue ) {
|
} elseif( Get-Command -ListImported Set-Theme -ErrorAction SilentlyContinue ) {
|
||||||
Set-Theme Paradox
|
Set-Theme Paradox
|
||||||
} elseif( Get-Module -ListAvailable posh-git -ErrorAction SilentlyContinue ) {
|
} elseif( Get-Module -ListAvailable posh-git -ErrorAction SilentlyContinue ) {
|
||||||
Import-Module posh-git
|
Import-Module posh-git
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||||
$local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot)
|
$local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot)
|
||||||
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
|
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
|
||||||
$local:hostname = $(hostname)
|
$local:hostname = $(hostname)
|
||||||
$local:allCmdlets = Get-Command | Select-Object -ExpandProperty Name
|
$local:allCmdlets = Get-Command -ListImported | Select-Object -ExpandProperty Name
|
||||||
|
|
||||||
$local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } )
|
$local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } )
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
|
||||||
}
|
}
|
||||||
if( $v -and $c.AppExeExists ) {
|
if( $v -and $c.AppExeExists ) {
|
||||||
$v = $v -and -not $($c.AppExeExists | Where-Object {
|
$v = $v -and -not $($c.AppExeExists | Where-Object {
|
||||||
-not ( Get-Command $_ -Type Application -ErrorAction SilentlyContinue )
|
-not ( Get-Command -ListImported $_ -Type Application -ErrorAction SilentlyContinue )
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if( $v -and $c.custom ) {
|
if( $v -and $c.custom ) {
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue