From 116238769665e163a85e01b4547caf6c8f506d83 Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Thu, 19 Sep 2024 03:48:42 +0000 Subject: [PATCH 1/4] fix(commands): Handdling broken aliases while listing them --- lib/commands.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/commands.ps1 b/lib/commands.ps1 index 04775de357..02e8e9c9d5 100644 --- a/lib/commands.ps1 +++ b/lib/commands.ps1 @@ -4,7 +4,7 @@ function command_files { (Get-ChildItem "$PSScriptRoot\..\libexec") + (Get-ChildItem "$scoopdir\shims") | - Where-Object 'scoop-.*?\.ps1$' -Property Name -Match + Where-Object 'scoop-.*?\.ps1$' -Property Name -Match } function commands { @@ -98,11 +98,19 @@ function list_aliases { $aliases = get_config ALIAS ([PSCustomObject]@{}) $alias_info = $aliases.PSObject.Properties.Name | Where-Object { $_ } | ForEach-Object { + # Mark the alias as , if the alias script file does NOT exist. + if (!(Test-Path "$(shimdir $false)\scoop-$_.ps1")) { + [PSCustomObject]@{ + Name = $_ + Command = '' + } + return + } $content = Get-Content (command_path $_) [PSCustomObject]@{ Name = $_ - Summary = (summary $content).Trim() Command = ($content | Select-Object -Skip 1).Trim() + Summary = (summary $content).Trim() } } if (!$alias_info) { From 081ef14ebe397ba00473043b3a606da25d52fe6b Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Thu, 19 Sep 2024 03:59:47 +0000 Subject: [PATCH 2/4] ignore error msg while removing broken alias --- lib/commands.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commands.ps1 b/lib/commands.ps1 index 02e8e9c9d5..2ee0404d77 100644 --- a/lib/commands.ps1 +++ b/lib/commands.ps1 @@ -86,7 +86,7 @@ function rm_alias { } info "Removing alias '$name'..." - Remove-Item "$(shimdir $false)\scoop-$name.ps1" + Remove-Item "$(shimdir $false)\scoop-$name.ps1" -ErrorAction SilentlyContinue $aliases.PSObject.Properties.Remove($name) set_config ALIAS $aliases | Out-Null } From 963303c8e11826fb40d89bc237a4ca39febb7edc Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Thu, 19 Sep 2024 04:14:31 +0000 Subject: [PATCH 3/4] execute remove operation when file exists instead of just ignore error --- lib/commands.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/commands.ps1 b/lib/commands.ps1 index 2ee0404d77..6812aebd52 100644 --- a/lib/commands.ps1 +++ b/lib/commands.ps1 @@ -86,7 +86,9 @@ function rm_alias { } info "Removing alias '$name'..." - Remove-Item "$(shimdir $false)\scoop-$name.ps1" -ErrorAction SilentlyContinue + if (Test-Path "$(shimdir $false)\scoop-$name.ps1") { + Remove-Item "$(shimdir $false)\scoop-$name.ps1" + } $aliases.PSObject.Properties.Remove($name) set_config ALIAS $aliases | Out-Null } From bbba2dc04dddec7d0de87c0f55e889f2601f1e80 Mon Sep 17 00:00:00 2001 From: HUMORCE Date: Thu, 19 Sep 2024 04:22:19 +0000 Subject: [PATCH 4/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76c04c961d..356486b519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - **scoop-download|install|update:** Fallback to default downloader when aria2 fails ([#4292](https://github.com/ScoopInstaller/Scoop/issues/4292)) - **decompress**: `Expand-7zipArchive` only delete temp dir / `$extractDir` if it is empty ([#6092](https://github.com/ScoopInstaller/Scoop/issues/6092)) +- **commands**: Handling broken aliases ([#6141](https://github.com/ScoopInstaller/Scoop/issues/6141)) ### Code Refactoring