-
Notifications
You must be signed in to change notification settings - Fork 52
Open
Description
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:
Metadata
Metadata
Assignees
Labels
No labels