Skip to content

Instantly share code, notes, and snippets.

@WorldMaker
Last active August 3, 2022 20:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment