You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
functiongcmsg {
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$splitPatternforeach ($partin$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 commandInvoke-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:
The text was updated successfully, but these errors were encountered:
I have been playing around with a modified version of the
gcmsg
function, just figured I would share whether it makes it in or notIt allows you to split on a delimiter and create multiple
-m
flags, which would simulate doing the followinggit commit -m "text" -m "text" -m "text"
, which gives you a nicer formatted message imhoNOTE: I use a
,
as the delimiterExample Usage:
Result in repo:
The text was updated successfully, but these errors were encountered: