Skip to content

Instantly share code, notes, and snippets.

@phense
Created August 8, 2023 06:11
Show Gist options
  • Save phense/f8d8f799a5d6ec5bb80dad7556b4053d to your computer and use it in GitHub Desktop.
Save phense/f8d8f799a5d6ec5bb80dad7556b4053d to your computer and use it in GitHub Desktop.
Powershell embedded in .CMD File; automatic git commit - pull - push
@@:: This prolog allows a PowerShell script to be embedded in a .CMD file.
@@:: Any non-PowerShell content must be preceeded by "@@"
@@setlocal
@@set POWERSHELL_BAT_ARGS=%*
@@if defined POWERSHELL_BAT_ARGS set POWERSHELL_BAT_ARGS=%POWERSHELL_BAT_ARGS:"=\"%
@@PowerShell -ExecutionPolicy Bypass -Command Invoke-Expression $('$args=@(^&{$args} %POWERSHELL_BAT_ARGS%);'+[String]::Join(';',$((Get-Content '%~f0') -notmatch '^^@@'))) & goto :EOF
Set-Location -Path "C:\Users\peter\Repositories\notes.git\"
$gstatus = git status --porcelain
$numberOfChanges = ($gstatus | Measure-Object).Count
$currentDateTime = Get-Date -Format "yyyy-MM-dd HH:mm"
if ($numberOfChanges -gt 0) {
$commitMessage = "$currentDateTime - files changed: $numberOfChanges"
git add --all
git commit -m $commitMessage
git pull
git push
}
Read-Host -Prompt "Press Enter to exit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment