Skip to content

Commit

Permalink
(#3364) Use new tab-expansion from PowerShell v5
Browse files Browse the repository at this point in the history
The newer method is available from v5 and up, so we have no need to wait
for v7.4+ to change over. This will also let us remove the fallback
earlier, once we no longer support PS <5.0.
  • Loading branch information
vexx32 authored and corbob committed Nov 4, 2024
1 parent 3be2a2b commit 53dc7e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ if ($PowerTab_RegisterTabExpansion) {
return
}

# PowerShell up to v7.3.x: use a custom TabExpansion function.
if ($PSVersionTable.PSVersion.Major -lt 7 -or ($PSVersionTable.PSVersion.Major -eq 7 -and $PSVersionTable.PSVersion.Minor -lt 4)) {
# PowerShell up to v5.x: use a custom TabExpansion function.
if ($PSVersionTable.PSVersion.Major -lt 5) {
if (Test-Path Function:\TabExpansion) {
Rename-Item Function:\TabExpansion TabExpansionBackup
}
Expand All @@ -288,7 +288,8 @@ if ($PSVersionTable.PSVersion.Major -lt 7 -or ($PSVersionTable.PSVersion.Major -
}
}
}
} else { # PowerShell v7.4+: use the Register-ArgumentCompleter cmdlet (PowerShell no longer calls TabExpansion)
}
else { # PowerShell v5+: use the Register-ArgumentCompleter cmdlet (PowerShell no longer calls TabExpansion after 7.4, but this available from 5.x)
function script:Get-AliasNames($exe) {
@($exe) + @(Get-Alias | Where-Object { $_.Definition -eq $exe } | Select-Object -Exp Name)
}
Expand Down
4 changes: 2 additions & 2 deletions src/chocolatey.resources/helpers/chocolateyProfile.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Import-Module "$thisDirectory\Chocolatey.PowerShell.dll" -Cmdlet "Get-Environmen
Set-Alias refreshenv Update-SessionEnvironment

Export-ModuleMember -Alias refreshenv -Cmdlet 'Update-SessionEnvironment'
if ($PSVersionTable.PSVersion.Major -lt 7 -or ($PSVersionTable.PSVersion.Major -eq 7 -and $PSVersionTable.PSVersion.Minor -lt 4)) {
Export-ModuleMember -Function 'TabExpansion' # Legacy TabExpansion function is only used up to PowerShell v7.3.x
if ($PSVersionTable.PSVersion.Major -lt 5) {
Export-ModuleMember -Function 'TabExpansion' # Legacy TabExpansion function is only used up to PowerShell v5.x
}

# SIG # Begin signature block
Expand Down

0 comments on commit 53dc7e0

Please sign in to comment.