Skip to content

Instantly share code, notes, and snippets.

@julianorchard
Created December 19, 2022 15:01
Show Gist options
  • Select an option

  • Save julianorchard/43d8e57bee440457dd27e47e1bcf796a to your computer and use it in GitHub Desktop.

Select an option

Save julianorchard/43d8e57bee440457dd27e47e1bcf796a to your computer and use it in GitHub Desktop.
A PowerShell helper for semantic commits.
## commit.ps1 --- Helper for creating semantic commits.
# Copyright (c) 2022 Julian Orchard <jorchard@pm.me>
## Description:
# Should be thought of as a temporary tool until used to doing it by default!
# Reminder text from this Gist:
# https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716
## Code:
$validCommitTypes = @(
'feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore')
$commitTypeDescriptions = @(
' -> new feature for the user, not a new feature for build script',
' -> bug fix for the user, not a fix to a build script',
' -> changes to the documentation',
' -> formatting, missing semi colons, etc; no production code change',
' -> refactoring production code, eg. renaming a variable',
' -> adding missing tests, refactoring tests; no production code change',
' -> updating grunt tasks etc; no production code change'
)
Write-Host(@"
Here are the types of commit that are valid:
"@)
# For: it's easier than ForEach in getting the current index of the array:
For ($i = 0; $i -le $validCommitTypes.length - 1; $i++) {
# gapChars is for aligning the output:
$gapChars = " " * (8 - $validCommitTypes[$i].Length)
Write-Host(" - '" + $validCommitTypes[$i] + "'" +
$gapChars + $commitTypeDescriptions[$i])
}
Write-Host ""
# Checking the user is inputting a valid commit type:
$checkInput = Read-Host "What type of commit is this? "
While (-Not ($validCommitTypes -Contains $checkInput)) {
$checkInput = Read-Host "What type of commit is this? "
}
$type = $checkInput
# Input commit message:
$msg = Read-Host("Commit message")
# Commit:
$commitMessage = $type + ": " + $msg
git commit -m "$commitMessage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment