Last active
May 8, 2025 05:53
-
-
Save WorldMaker/cba729e77226ecbff933b265d53f7823 to your computer and use it in GitHub Desktop.
PowerShell snippets
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
# 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() } | |
} |
This file contains hidden or 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
# 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