Skip to content

Instantly share code, notes, and snippets.

@WorldMaker
Last active May 8, 2025 05:53
Show Gist options
  • Save WorldMaker/cba729e77226ecbff933b265d53f7823 to your computer and use it in GitHub Desktop.
Save WorldMaker/cba729e77226ecbff933b265d53f7823 to your computer and use it in GitHub Desktop.
PowerShell snippets
# A simple wrapper function for the pattern of run a command and if the command succeeds
# commit all the changes to git with a git commit message of the command line prefixed
# with a wrench (🔧)
function Invoke-GitExpression {
param(
[string[]]
[Parameter(ValueFromRemainingArguments)]
$Remaining
)
Invoke-Expression "$Remaining"
if ($LASTEXITCODE -eq 0) {
git add -A
git commit -m "🔧 $Remaining"
}
}
Set-Alias wrench Invoke-GitExpression
# The http.exe wrapper for httpie (.org) keeps getting flagged as a false positive for malware by corporate security tools,
# so here's a wrapper function and alias to replace it by calling through the main Python exe.
function Invoke-Httpie {
param(
[string[]]
[Parameter(ValueFromRemainingArguments)]
$Remaining
)
python -m httpie $Remaining
}
Set-Alias http Invoke-Httpie
# A simple GUI multi-selector for removing merged git branches in reasonable bulk
function Remove-GitBranches {
git branch --merged | Out-GridView -Title "Branches to Remove?" -OutputMode Multiple | % { git branch -d $_.Trim() }
}
# Move to a PR merge commit by `(#number)` in commit name as detached git head
function Set-GitPullRequest {
param (
[string]$PullRequest
)
# using the GitHub `#` in the commit message to find the next PR commit hash
$commitHash = (git log --all --grep="\(#$PullRequest\)" -n 1 --format=format:%H)
git switch --detach $commitHash
}
Set-Alias cdpr Set-GitPullRequest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment