Skip to content

chore: Optimize PowerShell profile modification tool#18187

Open
AkariiinMKII wants to merge 3 commits into
ScoopInstaller:masterfrom
AkariiinMKII:update-pspm
Open

chore: Optimize PowerShell profile modification tool#18187
AkariiinMKII wants to merge 3 commits into
ScoopInstaller:masterfrom
AkariiinMKII:update-pspm

Conversation

@AkariiinMKII

Copy link
Copy Markdown
Contributor
  • Optimize processing logic and syntax
  • Enhance log output
  • Drop support for outdated calling methods deprecated from 2022
  • Update related manifests

Considering that the widely used built-in PowerShell version in Windows 10 is 5.1, and I'm not able to test on version 5.0, the required version has been upgraded to 5.1.

  • Use conventional PR title: <manifest-name[@version]|chore>: <general summary of the pull request>
  • I have read the Contributing Guide

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be66f179-f2d4-4252-9912-753f119eb05f

📥 Commits

Reviewing files that changed from the base of the PR and between cb77640 and 96ed1e9.

📒 Files selected for processing (1)
  • bucket/scoop-completion.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • bucket/scoop-completion.json

📝 Walkthrough

Walkthrough

ModifyPSProfile.psm1 raises the minimum PowerShell version to 5.1, renames New-ProfileModifier parameters to Behavior and AppName with aliases for the old names, and changes generated script writing to UTF-8 with [Environment]::NewLine. Add-ProfileContent now logs progress and uses try/catch with UTF-8 append-or-create logic. Remove-ProfileContent adds missing-profile checks, regex-based removal, UTF-8 rewrite, and reduces module exports to three functions. bucket/scoop-completion.json updates the notes text, switches to the renamed parameters, changes missing-file warnings, and gates uninstall cleanup on $cmd -eq 'uninstall'.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, conventional, and accurately reflects the main change to the PowerShell profile modification tool.
Description check ✅ Passed The description covers the summary and checklist items, but the issue reference section remains a placeholder.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
bucket/scoop-completion.json (1)

18-46: 📐 Maintainability & Code Quality | 🔵 Trivial

Please run the standard Scoop manifest checks before merge.

As per path instructions, test this manifest locally with the usual Scoop flow and include an uninstall pass, since this PR changes both post_install and pre_uninstall.

scoop config debug true
scoop config gh_token <your-github-token>  # optional; needed only for GitHub release API access
.\bin\checkver.ps1 -App scoop-completion -f
.\bin\formatjson.ps1 -App scoop-completion
scoop install bucket\scoop-completion.json -a <architecture>
scoop uninstall scoop-completion
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bucket/scoop-completion.json` around lines 18 - 46, The manifest change
touches both post_install and pre_uninstall in scoop-completion, so it needs the
standard Scoop validation flow before merge. Verify the manifest locally using
the usual Scoop checks via checkver.ps1 and formatjson.ps1, then test a real
install and uninstall cycle for scoop-completion to confirm the new
profile-modification cleanup works as expected.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/ModifyPSProfile.psm1`:
- Around line 140-144: The profile cleanup logic in ModifyPSProfile should only
remove the exact generated line, not any matching text anywhere in the file or
surrounding whitespace. Update the matching/removal in the script’s
profile-editing flow to anchor the regex to the generated line from the Content
value, and avoid using a global trim on the full profile so unrelated user
formatting is preserved. Use the existing $RawProfile, $escapedContent, and
$modifiedProfile flow to make the deletion precise and limited to the generated
import line.
- Around line 46-54: The generated Import-Module command in ModifyPSProfile is
emitting $UtilsPath unquoted, which breaks when the Scoop path contains spaces.
Update the command construction in the ModifyPSProfile logic so the path is
wrapped as a single quoted argument when building $ImportUtilsCommand, and keep
the add/remove script generation consistent by verifying the resulting
Import-Module string is safe for paths with spaces.
- Around line 58-73: The file I/O operations in the profile modification helpers
are not terminating, so failures can slip past the try/catch and still report
success. Update the file read/write calls in New-ProfileModifier,
Add-ProfileContent, and Remove-ProfileContent—especially the Out-File,
Add-Content, and Get-Content usages—to use -ErrorAction Stop so any I/O error is
caught by the existing catch blocks.
- Around line 96-100: The profile write path in ModifyPSProfile should ensure
the parent directory exists before writing, since Out-File -Force still fails
when $PROFILE points to a missing folder. Update the logic around Test-Path,
Add-Content, and Out-File to create the $PROFILE parent directory first, then
proceed with writing the profile content so first-run users do not hit the catch
block.

---

Nitpick comments:
In `@bucket/scoop-completion.json`:
- Around line 18-46: The manifest change touches both post_install and
pre_uninstall in scoop-completion, so it needs the standard Scoop validation
flow before merge. Verify the manifest locally using the usual Scoop checks via
checkver.ps1 and formatjson.ps1, then test a real install and uninstall cycle
for scoop-completion to confirm the new profile-modification cleanup works as
expected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 06611a41-34ad-4589-9f1f-f9668a957203

📥 Commits

Reviewing files that changed from the base of the PR and between de1260c and 2d7a297.

📒 Files selected for processing (2)
  • bucket/scoop-completion.json
  • scripts/ModifyPSProfile.psm1

Comment thread scripts/ModifyPSProfile.psm1
Comment thread scripts/ModifyPSProfile.psm1
Comment thread scripts/ModifyPSProfile.psm1
Comment thread scripts/ModifyPSProfile.psm1 Outdated
@AkariiinMKII

Copy link
Copy Markdown
Contributor Author

/verify

@github-actions

Copy link
Copy Markdown
Contributor

All changes look good.

Wait for review from human collaborators.

scoop-completion

  • Lint
  • Description
  • License
  • Hashes
  • Checkver
  • Autoupdate

Check the full log for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant