mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-07-01 07:59:36 +02:00
Compare commits
3 Commits
copilot/up
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6d5967b69 | ||
|
|
129f0a33a0 | ||
|
|
2cea99965b |
@@ -51,6 +51,15 @@ if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contai
|
||||
}
|
||||
elseif ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")))
|
||||
{
|
||||
# Upgrade unconditional import to conditional to avoid crashes in non-interactive sessions (e.g. VS Code tasks)
|
||||
if ($profileContent.Contains("Import-Module -Name Microsoft.WinGet.CommandNotFound") -and (-not $profileContent.Contains("GetCommandLineArgs")))
|
||||
{
|
||||
$conditionalImport = @'
|
||||
if (-not ([Environment]::GetCommandLineArgs() | Where-Object { $_ -in @('-Command','-c','-EncodedCommand','-e','-ec','-File','-f','-NonInteractive') })) { Import-Module -Name Microsoft.WinGet.CommandNotFound }
|
||||
'@
|
||||
$profileContent = $profileContent.Replace("Import-Module -Name Microsoft.WinGet.CommandNotFound", $conditionalImport)
|
||||
Set-Content -Path $PROFILE -Value $profileContent
|
||||
}
|
||||
Write-Host "Command Not Found module is registered in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
|
||||
@@ -55,12 +55,18 @@ if (!(Test-Path $PROFILE))
|
||||
|
||||
$profileContent = Get-Content -Path $PROFILE -Raw
|
||||
|
||||
# Only import in interactive sessions to avoid crashes when PowerShell exits quickly (e.g. VS Code tasks).
|
||||
# Command Not Found is a feedback provider only useful in interactive sessions.
|
||||
$conditionalImport = @'
|
||||
if (-not ([Environment]::GetCommandLineArgs() | Where-Object { $_ -in @('-Command','-c','-EncodedCommand','-e','-ec','-File','-f','-NonInteractive') })) { Import-Module -Name Microsoft.WinGet.CommandNotFound }
|
||||
'@
|
||||
|
||||
if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("34de4b3d-13a8-4540-b76d-b9e8d3851756")))
|
||||
{
|
||||
if ($profileContent.Contains("Import-Module `"$scriptPath\WinGetCommandNotFound.psd1`""))
|
||||
{
|
||||
$profileContent = $profileContent.Replace("Import-Module `"$scriptPath\WinGetCommandNotFound.psd1`"",
|
||||
"Import-Module -Name Microsoft.WinGet.CommandNotFound")
|
||||
$conditionalImport)
|
||||
$profileContent = $profileContent.Replace("34de4b3d-13a8-4540-b76d-b9e8d3851756",
|
||||
"f45873b3-b655-43a6-b217-97c00aa0db58")
|
||||
Set-Content -Path $PROFILE -Value $profileContent
|
||||
@@ -70,13 +76,23 @@ if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contai
|
||||
}
|
||||
elseif ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contains("f45873b3-b655-43a6-b217-97c00aa0db58")))
|
||||
{
|
||||
Write-Host "Module is already registered in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
if ($profileContent.Contains("Import-Module -Name Microsoft.WinGet.CommandNotFound") -and (-not $profileContent.Contains("GetCommandLineArgs")))
|
||||
{
|
||||
$profileContent = $profileContent.Replace("Import-Module -Name Microsoft.WinGet.CommandNotFound", $conditionalImport)
|
||||
Set-Content -Path $PROFILE -Value $profileContent
|
||||
Write-Host "Module was successfully upgraded in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Module is already registered in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Add-Content -Path $PROFILE -Value "`r`n#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module"
|
||||
Add-Content -Path $PROFILE -Value "`r`nImport-Module -Name Microsoft.WinGet.CommandNotFound"
|
||||
Add-Content -Path $PROFILE -Value "`r`n$conditionalImport"
|
||||
Add-Content -Path $PROFILE -Value "#f45873b3-b655-43a6-b217-97c00aa0db58"
|
||||
Write-Host "Module was successfully registered in the profile file."
|
||||
# This message will be compared against in Command Not Found Settings page code behind. Take care when changing it.
|
||||
|
||||
@@ -19,10 +19,15 @@ if ((-not [string]::IsNullOrEmpty($profileContent)) -and ($profileContent.Contai
|
||||
}
|
||||
|
||||
# Replace old module with new one (and new GUID comment)
|
||||
# Use conditional import to avoid crashes when PowerShell exits quickly (e.g. VS Code tasks)
|
||||
$conditionalImport = @'
|
||||
if (-not ([Environment]::GetCommandLineArgs() | Where-Object { $_ -in @('-Command','-c','-EncodedCommand','-e','-ec','-File','-f','-NonInteractive') })) { Import-Module -Name Microsoft.WinGet.CommandNotFound }
|
||||
'@
|
||||
$regex = "Import-Module .*WinGetCommandNotFound.psd1`""
|
||||
if ($profileContent -match $regex)
|
||||
$match = [regex]::Match($profileContent, $regex)
|
||||
if ($match.Success)
|
||||
{
|
||||
$profileContent = $profileContent -replace $regex, "Import-Module -Name Microsoft.WinGet.CommandNotFound"
|
||||
$profileContent = $profileContent.Replace($match.Value, $conditionalImport)
|
||||
$profileContent = $profileContent -replace $legacyGuid, "f45873b3-b655-43a6-b217-97c00aa0db58"
|
||||
Set-Content -Path $PROFILE -Value $profileContent
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user