Quantcast
Viewing all articles
Browse latest Browse all 17

using git for journaling, part 2

Image may be NSFW.
Clik here to view.

In a previous post, I explained how you can use Git for journaling, or keeping a work log. I’ve been using this for a while, and of course I’ve been writing a bit of a PowerShell script to make this easier, and not have to use the Git commands all the time.

Here’s how I add an entry to today’s log:

wl "Worked on project X"

This also works:

wl -add "Worked on project X"

Easy enough right? Listing what’s in the log for the last days is even easier.

wl

Or more verbosely:

wl -list

It’ll output something like this:

*** Friday 23 August 2024 ***

Worked on project X

*** Thursday 22 August 2024 ***

Project X setup
Knowledge sharing meeting

It goes back 4 days (as I usually need this on Friday), but if you want to go back further you can do something like this:

wl -list -entries 10

Sounds good? Well, here’s the script code. Put this in a script file called wl.ps1 or whatever name you fancy, and put it in your system path somewhere.

The script assumes your Git journaling repository is located in your home directory, named worklog. It’s that $path parameter at line 3, so feel free to change that. If you don’t like the 4 days history, you can also update the default value of the $Entries parameter in the first line.

param([switch]$List, [switch]$Add, [string]$Message, $Entries=4)

$path = "`~\worklog"

if ($List -or $Message -eq "") {
    pushd
    cd $path

    $dateStart = (Get-Date).AddDays(-$_).ToString("yyyy-MM-dd")
    $dateEnd = (Get-Date).AddDays((-$_)-$Entries).ToString("yyyy-MM-dd")

    $log= git log --format="format:%as;%s" --before $dateStart --after $dateEnd 

    $prevDate = ""
    $log | % {
        $date, $msg = $_ -split ";"

        if ($prevDate -ne $date) {
            $prevDate = $date
            Write-Host "`n*** $((get-date($date)).ToLongDateString()) ***`n" -ForegroundColor Cyan
        }

        Write-Host "- $msg"
    }

    Write-Host ""

    popd

} else {

    if ($Add -or ($Message -ne "")) {
        pushd
        cd $path
        git commit -m $message --allow-empty | Out-Null
        popd
        Write-Host "Log added."
    }
}

The post using git for journaling, part 2 appeared first on n3wjack's blog.


Viewing all articles
Browse latest Browse all 17

Trending Articles