Skip to content

Instantly share code, notes, and snippets.

@jjorissen52
Created April 22, 2021 20:57
Show Gist options
  • Save jjorissen52/a83bb04f00b8b21a3c6d4bf01a7866c1 to your computer and use it in GitHub Desktop.
Save jjorissen52/a83bb04f00b8b21a3c6d4bf01a7866c1 to your computer and use it in GitHub Desktop.
Mining Git Commits

Here is a simple proof-of-concept for viewing your most recent commits machine-wide using nushell!

Start nushell:

nu

Load the script below (with modifications for your machine, of course) and run your pipeline:

source /path/to/git-show.nu

# Shows your commits since April! You'll want to modify the is-me command.
git-mine | where merged_at > "2021-04-01"

# Shows your last 20 non-merge commits
git-all | skip-merge | where committer =~ "<me>" | first 20
#!/usr/local/bin/nu
def repo-show [] {
ls -a ~/*Projects/*/.git | where type == "Dir"
}
def git-show [
--repo (-r): string # path to repository
--head (-h): int # Restrict the output to the first n lines
--tail (-t): int # Restrict the output to the last n lines
] {
let repo = $(if $(echo $repo | empty?) {
echo "."
} {
echo $repo
})
let log = $(echo; git -C $repo log --date=format:'%Y-%m-%d %H:%M:%S' --pretty=%h»¦«%aN»¦«%s»¦«%cd | lines | split column "»¦«" sha1 committer desc merged_at)
let log = $(echo $log | insert repo $repo)
let log = $(if $(echo $head | empty?) {
echo $log
} {
echo $log | first $head
})
let log = $(if $(echo $tail | empty?) {
echo $log
} {
echo $log | last $tail
})
echo $log
}
def git-all [] {
repo-show | get name | each { git-show --repo $it }
}
def is-me [] {
each {
echo $it | where committer =~ "jorissen" || committer =~ "Jorissen"
}
}
def skip-merge [] {
each {
echo $it | where desc !~ "Merge" && desc !~ "merge"
}
}
def git-mine [] {
git-all | skip-merge | sort-by merged_at -r | is-me
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment