Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative gcmsg idea #46

Open
ondrovic opened this issue Aug 24, 2024 · 0 comments
Open

Alternative gcmsg idea #46

ondrovic opened this issue Aug 24, 2024 · 0 comments

Comments

@ondrovic
Copy link

ondrovic commented Aug 24, 2024

I have been playing around with a modified version of the gcmsg function, just figured I would share whether it makes it in or not

function gcmsg {
    param(
        [Parameter(Mandatory=$true)]
        [string]$message,
        [string]$delimiter = ',',
        [switch]$capitalizeNewLine,
        [switch]$dryRun
    )

    $commitMessages = @()

    # Create a regex pattern based on the delimiter
    $delimiterPattern = [regex]::Escape($delimiter)
    $splitPattern = "\s*$delimiterPattern\s*"

    # Split the message by the delimiter, handling various spacing
    $parts = $message -split $splitPattern

    foreach ($part in $parts) {
        if (-not [string]::IsNullOrWhiteSpace($part)) {
            if ($capitalizeNewLine) {
                # Capitalize the first letter only if the switch is set
                $processedPart = $part.Substring(0,1).ToUpper() + $part.Substring(1)
            } else {
                $processedPart = $part
            }
            
            $commitMessages += "-m"
            $commitMessages += "`"$processedPart`""
        }
    }

    # Join the commit messages into a single string
    $gitCommand = "git commit $($commitMessages -join ' ')"
    
    if ($dryRun) {
        Write-Host $gitCommand
    } else {
        # Execute the git command
        Invoke-Expression $gitCommand
    }
}

It allows you to split on a delimiter and create multiple -m flags, which would simulate doing the following

git commit -m "text" -m "text" -m "text", which gives you a nicer formatted message imho

NOTE: I use a , as the delimiter

Example Usage:

# Works same as current function
input: gcmsg "Updates"
results: git commit -m "Updates"

# Inline `-`
input: gcmsg "Updates , i updated a file,I refactored a func "
results git commit -m "Updates" -m "I updated a file" -m "I refactored a func"

Result in repo:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant