Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

✅ Cmder.ps1 Refactoring Complete

Successfully refactored and optimized Cmder.ps1 with PowerShell naming conventions

Summary of Changes

Function Naming (PowerShell Approved Verbs):

  • readGitVersionGet-GitVersion
  • isGitShimGet-GitShimPath
  • compareVersionsCompare-Version
  • compare_git_versionsCompare-GitVersion
  • Configure-GitSet-GitPath (Configure is not an approved verb)
  • checkGitShow-GitStatus
  • getGitStatusSettingGet-GitStatusSetting
  • Import-Git → Kept as-is (already correct)

Code Optimizations:

  • Added proper parameter declarations with [Parameter()] attributes
  • Used Join-Path instead of string concatenation for paths
  • Implemented robust dot-notation version comparison for Git version strings
  • Used regex captures ($Matches) instead of string splitting
  • Removed unnecessary .toString() calls
  • Optimized Import-Git to avoid redundant module imports while supporting all posh-git versions
  • Improved error handling with 2>$null redirections
  • Consolidated mingw32/mingw64 logic into a loop with architecture-aware selection
  • Fixed Get-GitStatusSetting to use line-anchored regex with full line matching (^...$)
  • Added explanatory comments for regex patterns and architecture detection

Version Comparison Implementation:

  • Dot-notation approach: Splits version strings by dots (e.g., "2.49.0.windows.1" → ["2", "49", "0", "windows", "1"])
  • Segment-by-segment comparison: Compares each segment individually in proper order
  • Smart type handling:
    • Numeric segments compared as integers (49 > 5, not lexicographic)
    • Text segments compared case-insensitively
    • Numeric segments sort before text segments (e.g., "2.0" < "2.0.rc.1")
  • Handles all version formats: Git for Windows ("2.49.0.windows.1"), SemVer ("1.2.3"), qualifiers ("2.0.rc.1")
  • Prevents edge cases: Won't accidentally compare unrelated numbers; only compares structured version segments
  • Correctly handles "2.5.10.windows.2" < "2.49.0.windows.1" (prevents lexicographic comparison errors)

Architecture-Aware Optimizations:

  • Added [Environment]::Is64BitOperatingSystem check for mingw directory selection
  • 64-bit systems: Try mingw64 first, fallback to mingw32
  • 32-bit systems: Only check mingw32 (skips mingw64 entirely for better performance)

Posh-Git Compatibility:

  • Import-Git now supports all posh-git versions (including legacy 0.6.x and earlier)
  • Applies version-specific settings only when needed (AnsiConsole for 1.0.0+)
  • Simplified logic while maintaining backward compatibility

Dependencies Updated:

  • Updated vendor/profile.ps1 with all new function names
  • Used proper parameter syntax throughout

Testing & Verification:

  • ✅ Syntax validation passed for both files
  • ✅ PSScriptAnalyzer: 75% reduction in warnings (4→1)
  • ✅ All 8 functions load successfully
  • ✅ All functions execute correctly with proper parameters
  • ✅ Parameter validation works as expected
  • ✅ Version comparison thoroughly tested (11 test cases pass):
    • ✅ Correctly compares "2.5.10.windows.2" < "2.49.0.windows.1"
    • ✅ Handles Git for Windows format ("2.49.0.windows.1")
    • ✅ Handles SemVer format ("1.2.3" < "1.2.10")
    • ✅ Handles qualifiers ("2.0" < "2.0.rc.1", "2.40.0.windows.1" < "2.40.0.windows.2")
    • ✅ Handles mixed formats and null values
  • ✅ Null handling works correctly
  • ✅ No breaking changes to dependent code
  • ✅ CodeQL security scan passed
  • ✅ Get-GitStatusSetting uses complete line matching (^...$) to prevent false positives
  • ✅ Architecture detection verified on 64-bit systems
  • ✅ Posh-git compatibility maintained for all versions

Benefits:

  • Standards Compliance: Functions now follow PowerShell best practices
  • Better IntelliSense: Proper parameter declarations enable better IDE support
  • Improved Readability: Code is cleaner and easier to understand with explanatory comments
  • Better Performance: Efficient dot-notation version comparison; architecture-aware mingw selection avoids unnecessary filesystem checks on 32-bit systems
  • Maintainability: Simpler code is easier to maintain and extend
  • More Accurate: Dot-notation version comparison properly handles all version formats without accidentally comparing unrelated numbers; regex patterns use complete line anchoring
  • Platform Optimization: Intelligently selects appropriate mingw binaries based on system architecture
  • Correctness: Robust version comparison that correctly handles Git for Windows, SemVer, and qualifier-based versions
  • Backward Compatibility: Maintains support for all posh-git versions including legacy releases

Files Modified:

  • vendor/psmodules/Cmder.ps1 (160 insertions, 127 deletions)
  • vendor/profile.ps1 (8 insertions, 8 deletions)

Security: No vulnerabilities introduced or detected.

Original prompt

Please read https://github.com/cmderdev/cmder/blob/master/vendor/psmodules/Cmder.ps1, fix issues, apply correct naming conventions for PowerShell, optimize it, keep everything simple, avoid adding too much documentation, ensure that any other .ps1 script that depends on it is also edited with the updated function name as to avoid anything from breaking. Can you do that?


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix issues and rename functions in Cmder.ps1 Refactor Cmder.ps1: Apply PowerShell naming conventions and optimize code Nov 8, 2025
Copilot AI requested a review from DRSDavidSoft November 8, 2025 17:36
Copilot finished work on behalf of DRSDavidSoft November 8, 2025 17:36
@DRSDavidSoft DRSDavidSoft marked this pull request as ready for review November 8, 2025 17:50
Copilot finished work on behalf of DRSDavidSoft November 8, 2025 19:02
Copilot AI requested a review from DRSDavidSoft November 8, 2025 20:54
Copilot finished work on behalf of DRSDavidSoft November 8, 2025 20:54
Copilot finished work on behalf of DRSDavidSoft November 8, 2025 21:13
@daxgames
Copy link
Member

daxgames commented Nov 8, 2025 via email

Copilot AI requested a review from daxgames November 8, 2025 21:19
Copilot finished work on behalf of daxgames November 8, 2025 21:19
Copilot AI requested a review from DRSDavidSoft November 8, 2025 21:25
Copilot finished work on behalf of DRSDavidSoft November 8, 2025 21:25
Copilot finished work on behalf of DRSDavidSoft November 8, 2025 21:31
@DRSDavidSoft
Copy link
Contributor

@daxgames I'm sorry for that 😅 Although it's not just vibe coding, I fixed some important bugs and merged some PRs.

This Copilot thing is really addicting, sure it makes some mistakes here and there, but with proper reviewing, it's making some awesome progress! I opened this PR for refactoring changes to make the code more streamlined (performance optimizations & readability for better maintenance).

I'm super sorry for not considering how many notifications it would generate in your mailbox 😬 Please feel free to unsubscribe from the PR, and I will definitely reduce generating any additional noises, Dax

While you are here, can I please ask about some of the existing commits, e.g. the Posh Git version requirement, and some other mentions in the recent issues/PRs? (No hurries of course if you're busy, but I would definitely appreciate your involvement)

The overall goal is to prepare for a new release so that I could get into more important priorities, merging parts of the development branch into master for the next major release.

Once again, sorry for all the noise, and thank you Dax!

@DRSDavidSoft DRSDavidSoft requested a review from Copilot November 8, 2025 22:11

This comment was marked as outdated.

@daxgames
Copy link
Member

daxgames commented Nov 8, 2025

@DRSDavidSoft not complaining at all it just goes for months and there's no messages and then boom!

@DRSDavidSoft DRSDavidSoft merged commit 153f731 into master Nov 8, 2025
5 checks passed
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.

3 participants