mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-21 15:33:15 +01:00
Updated watch-commits.ps1
This commit is contained in:
parent
62eef6a209
commit
fab7a776fe
@ -1,12 +1,12 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Show commits live in real-time.
|
Watch commits live.
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script permanently lists the latest commit in a Git repository in real-time.
|
This PowerShell script continuously lists the latest commit in a Git repository in real-time.
|
||||||
.PARAMETER pathToRepo
|
.PARAMETER pathToRepo
|
||||||
Specifies the file path to the local Git repository.
|
Specifies the file path to the local Git repository.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./commit-ticker.ps1
|
PS> ./watch-commits.ps1
|
||||||
❇️ Updated general.csv by Markus Fleschutz (HEAD -> main, origin/main, origin/HEAD)
|
❇️ Updated general.csv by Markus Fleschutz (HEAD -> main, origin/main, origin/HEAD)
|
||||||
...
|
...
|
||||||
.LINK
|
.LINK
|
||||||
@ -22,31 +22,31 @@ try {
|
|||||||
$null = (git --version)
|
$null = (git --version)
|
||||||
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
|
||||||
|
|
||||||
Write-Progress "Checking file patch to Git repository..."
|
Write-Progress "Checking local Git repository..."
|
||||||
if (-not(Test-Path "$pathToRepo" -pathType container)) { throw "Can't access directory: $pathToRepo" }
|
if (-not(Test-Path "$pathToRepo" -pathType container)) { throw "Can't access directory: $pathToRepo" }
|
||||||
|
|
||||||
Write-Progress "Fetching updates..."
|
|
||||||
& git -C "$pathToRepo" fetch --all --recurse-submodules=no --jobs=1 --quiet
|
|
||||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
|
||||||
Write-Progress -completed "Done."
|
Write-Progress -completed "Done."
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "TIME COMMIT"
|
||||||
|
Write-Host "---- ------"
|
||||||
$prevLine = ""
|
$prevLine = ""
|
||||||
$tzOffset = (Get-Timezone).BaseUtcOffset.TotalSeconds
|
$tzOffset = (Get-Timezone).BaseUtcOffset.TotalSeconds
|
||||||
for (;;) {
|
for (;;) {
|
||||||
$line = (git -C "$pathToRepo" log origin --format=format:'%at %s by %an%d' --max-count=1)
|
|
||||||
if ($line -ne $prevLine) {
|
|
||||||
$unixTimestamp = [int64]$line.Substring(0,10)
|
|
||||||
$time = (Get-Date -day 1 -month 1 -year 1970 -hour 0 -minute 0 -second 0).AddSeconds($unixTimestamp)
|
|
||||||
$time = $time.AddSeconds($tzOffset)
|
|
||||||
$timeString = $time.ToString("HH:mm")
|
|
||||||
$message = $line.Substring(11)
|
|
||||||
& "$PSScriptRoot/write-typewriter.ps1" "❇️ $timeString $message" $speed
|
|
||||||
$prevLine = $line
|
|
||||||
} else {
|
|
||||||
Start-Sleep -seconds $updateInterval
|
|
||||||
}
|
|
||||||
& git -C "$pathToRepo" fetch --all --recurse-submodules=no --jobs=1 --quiet
|
& git -C "$pathToRepo" fetch --all --recurse-submodules=no --jobs=1 --quiet
|
||||||
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
if ($lastExitCode -ne "0") { throw "'git fetch' failed" }
|
||||||
|
|
||||||
|
$line = (git -C "$pathToRepo" log origin --format=format:'%at %s by %an%d' --max-count=1)
|
||||||
|
if ($line -eq $prevLine) {
|
||||||
|
Start-Sleep -seconds $updateInterval
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
$unixTimestamp = [int64]$line.Substring(0,10)
|
||||||
|
$time = (Get-Date -day 1 -month 1 -year 1970 -hour 0 -minute 0 -second 0).AddSeconds($unixTimestamp)
|
||||||
|
$time = $time.AddSeconds($tzOffset)
|
||||||
|
$timeString = $time.ToString("HH:mm")
|
||||||
|
$message = $line.Substring(11)
|
||||||
|
& "$PSScriptRoot/write-typewriter.ps1" "$timeString $message" $speed
|
||||||
|
$prevLine = $line
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user