Created
April 9, 2025 14:15
-
-
Save shmup/2454e2bd2c152d14eae73bec39cad3a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module posh-git | |
Import-Module PSFzf | |
# Set initial directory | |
cd "$HOME\workspace\repos\UI" | |
# Git aliases | |
Set-Alias -Name g -Value git | |
Remove-Item alias:gc -Force -ErrorAction SilentlyContinue | |
function gs { git status $args } | |
function gd { git diff $args } | |
function gc { git checkout $args } | |
function gdc { git diff --cached $args } | |
function grc { git rebase --continue $args } | |
function gap { git add -p $args } | |
function gsk { git stash --keep-index $args } | |
# Application aliases | |
Set-Alias -Name npp -Value 'C:\Program Files\Notepad++\notepad++.exe' | |
# Bash-like history navigation | |
Set-PSReadLineKeyHandler -Key 'Ctrl+p' -Function HistorySearchBackward | |
Set-PSReadLineKeyHandler -Key 'Ctrl+n' -Function HistorySearchForward | |
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | |
# Bash-like cursor movement | |
Set-PSReadLineKeyHandler -Key 'Ctrl+a' -Function BeginningOfLine # Move to start of line | |
Set-PSReadLineKeyHandler -Key 'Ctrl+e' -Function EndOfLine # Move to end of line | |
Set-PSReadLineKeyHandler -Key 'Ctrl+b' -Function BackwardChar # Move left one character | |
Set-PSReadLineKeyHandler -Key 'Ctrl+f' -Function ForwardChar # Move right one character | |
# Bash-like text editing | |
Set-PSReadLineKeyHandler -Key 'Ctrl+u' -Function BackwardDeleteLine # Delete from cursor to start | |
Set-PSReadLineKeyHandler -Key 'Ctrl+k' -Function ForwardDeleteLine # Delete from cursor to end | |
Set-PSReadLineKeyHandler -Key 'Ctrl+w' -Function BackwardDeleteWord # Delete previous word | |
Set-PSReadLineKeyHandler -Key 'Ctrl+y' -Function Paste # Paste deleted text | |
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete | |
# Enable PSFzf key bindings | |
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' -PSReadlineChordReverseHistory 'Ctrl+r' | |
function Get-GitBranches { | |
git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:relative)%09%(refname:short)' | |
} | |
function gco { | |
$selection = Get-GitBranches | fzf --height 40% --reverse | |
if ($selection) { | |
# Extract just the branch name (everything after the tab character) | |
$branch = $selection -replace '^.*?\t', '' | |
git checkout $branch | |
} | |
} | |
function Get-GitWorkSummary { | |
param ( | |
[Parameter(Mandatory=$false)] | |
[string]$Author = "Jared", | |
[Parameter(Mandatory=$false)] | |
[string]$Since = "1 month ago", | |
[Parameter(Mandatory=$false)] | |
[string]$Until = "now", | |
[Parameter(Mandatory=$false)] | |
[string]$RepoPath = "$HOME\workspace\repos\UI", | |
[Parameter(Mandatory=$false)] | |
[switch]$ExportToClipboard | |
) | |
Push-Location $RepoPath | |
# Get detailed git log with dates and commit messages | |
$gitLog = git log --since="$Since" --until="$Until" --author="$Author" --date=short --pretty=format:"%ad|%h|%s" | |
# Group commits by date | |
$commitsByDate = @{} | |
foreach ($line in $gitLog) { | |
$parts = $line -split '\|' | |
$date = $parts[0] | |
$hash = $parts[1] | |
$message = $parts[2] | |
if (-not $commitsByDate.ContainsKey($date)) { | |
$commitsByDate[$date] = @() | |
} | |
$commitsByDate[$date] += "$message [$hash]" | |
} | |
# Build formatted output | |
$output = "# Work Activity Summary ($Since to $Until)`n`n" | |
foreach ($date in $commitsByDate.Keys | Sort-Object) { | |
$output += "## $date ($(Get-Date $date -Format 'dddd'))`n" | |
foreach ($commit in $commitsByDate[$date]) { | |
$output += "- $commit`n" | |
} | |
$output += "`n" | |
} | |
# Output to console | |
Write-Output $output | |
# Copy to clipboard if requested | |
if ($ExportToClipboard) { | |
$output | Set-Clipboard | |
Write-Host "Work summary copied to clipboard!" -ForegroundColor Green | |
} | |
Pop-Location | |
} | |
function Get-InvoiceItems { | |
param ( | |
[Parameter(Mandatory=$false)] | |
[string]$Author = "Jared", | |
[Parameter(Mandatory=$false)] | |
[string]$Since = "2 months ago", # Extended timeframe | |
[Parameter(Mandatory=$false)] | |
[switch]$CopyToClipboard, | |
[Parameter(Mandatory=$false)] | |
[switch]$IncludeCommitDetails | |
) | |
# Get ALL your commits in the date range | |
$rawOutput = git log --pretty=format:"%ad|%H|%s" --date=short --author="$Author" --since="$Since" | |
# Process each commit line | |
$items = @() | |
foreach ($line in $rawOutput -split "`n") { | |
$parts = $line -split '\|' | |
if ($parts.Count -ge 3) { | |
$date = $parts[0] | |
$hash = $parts[1] | |
$message = $parts[2] | |
# Skip merge commits if desired | |
#if ($message -match "^Merge" -and -not $IncludeMergeCommits) { continue } | |
# Try to extract meaningful description | |
if ($message -match "^(.*?) \(#\d+\)$" -or $message -match "^(.*)$") { | |
$description = $matches[1] | |
# Only add unique work items | |
if (-not ($items | Where-Object { $_.Story -eq $description })) { | |
$item = [PSCustomObject]@{ | |
Date = $date | |
Story = $description | |
} | |
if ($IncludeCommitDetails) { | |
$item | Add-Member -NotePropertyName "CommitHash" -NotePropertyValue $hash | |
} | |
$items += $item | |
} | |
} | |
} | |
} | |
# Display as table | |
$items | Format-Table -AutoSize | |
# Copy to clipboard if requested | |
if ($CopyToClipboard) { | |
$items | Format-Table -AutoSize | Out-String | Set-Clipboard | |
Write-Host "Invoice items copied to clipboard!" -ForegroundColor Green | |
} | |
} | |
function ccopy { | |
$input | Set-Clipboard | |
Write-Host "Copied to clipboard!" -ForegroundColor Green | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I installed posh-git (cuter prompt that shows which branch you're in and etc), and PSFzF (fuzzy finder for files) via: