Skip to content

Instantly share code, notes, and snippets.

@gwennlbh
Last active October 10, 2025 20:44
Show Gist options
  • Save gwennlbh/eb7613b3733b1d48c24fe632ed0c7f15 to your computer and use it in GitHub Desktop.
Save gwennlbh/eb7613b3733b1d48c24fe632ed0c7f15 to your computer and use it in GitHub Desktop.
# For PowerShell v7
Invoke-Expression (&starship init powershell)
Invoke-Expression (& { (zoxide init powershell | Out-String) })
Set-PSReadlineOption -EditMode vi
Import-Module posh-git
function mkgitignore {
$params = ($args | ForEach-Object { [uri]::EscapeDataString($_) }) -join ","
$url = "https://www.toptal.com/developers/gitignore/api/$params"
Invoke-WebRequest -Uri $url | select -ExpandProperty content > $(join-path $pwd .gitignore)
}
function ln($existing, $destination) {
New-Item -Path $destination -ItemType SymbolicLink -Value $existing
}
Set-Alias lg lazygit
function gj {
gitmoji commit
}
function linux {
wsl --exec $args
}
# so meta woaaw,, :3
function editprofile {
nvim $profile
gh gist edit eb7613b3733b1d48c24fe632ed0c7f15 $profile
. $profile
}
function groot {
cd $(git rev-parse --show-toplevel)
}
function hawk {
echo tuah
}
function quoi {
echo coubeh
}
function bak {
foreach ($f in $args) {
cp $f "$f.bak"
}
}
function gitignore {
foreach ($pattern in $args) {
"$pattern" -replace "`\`\", "/" -replace "^`\./", "" >> .gitignore
}
}
#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module
Import-Module -Name Microsoft.WinGet.CommandNotFound
#f45873b3-b655-43a6-b217-97c00aa0db58
# in-place jq
function jqi {
$expr = $args[0]
foreach ($file in $args[1..$args.count]) {
jq "$expr" $file > "$file.jqitmp"
rm $file
mv "$file.jqitmp" $file
}
}
function linecount {
($input | measure-object -Line).lines
}
# https://stackoverflow.com/a/56036054/9943464
function speak {
# Create a new SpVoice objects
$voice = New-Object -ComObject Sapi.spvoice
# Set the speed - positive numbers are faster, negative numbers, slower
$voice.rate = 0
# Say something
$voice.speak($args -join " ")
}
function notify {
[System.Media.SystemSounds]::Asterisk.Play()
msg * ($args -join " ")
}
function vps {
linux ssh [email protected] $args
}
function wait-until-pr-merged($number, $interval, $repo) {
if ($interval -eq $null) {
$interval = 10
}
while ($(gh pr view $number --json state --jq .state) -eq "OPEN") {
sleep $interval
}
}
function base64-encode-file($file) {
[char[]][Convert]::ToBase64String([IO.File]::ReadAllBytes($file))
}
function base64-decode-file($encodedFile, $destination) {
[IO.File]::WriteAllBytes($destination, [Convert]::FromBase64String([char[]][IO.File]::ReadAllBytes($encodedFile)))
}
function wait-until-run-finishes($workflow) {
$run_id = $(gh run list --status in_progress --workflow $workflow --json databaseId --jq '.[0].databaseId')
if ("$run_id" -eq "") {
echo "No runs are currently in progress for workflow $workflow"
}
$run_commit = $(gh run view $run_id --json headSha --jq .headSha)
echo "Waiting for run $run_id on $run_commit"
git show --no-patch --pretty=format:%s $run_commit
while ($(gh run view $run_id --json status --jq .status) -eq "in_progress") {
sleep 10
}
echo "Run finished, see logs at $(gh run view $run_id --json url --jq .url)"
}
function prune-pr-branches {
foreach ($branch in $(git for-each-ref --format="%(refname:short)" refs/heads/)) {
$pr_no=$(gh pr list --state all -S "head:$branch" --json number --jq .[0].number)
if ("$pr_no" -eq "") {
echo "$branch has no associate PR"
echo ""
echo ""
continue
}
$status=$(gh pr view $pr_no --json state --jq .state)
echo "$branch is pr $pr_no, which is $status"
switch ($status) {
"CLOSED" { git branch -D $branch }
"MERGED" { git branch -D $branch }
"OPEN" { echo "Keeping $branch" }
}
echo ""
}
}
function killport($port) {
$target_pid = (Get-NetTCPConnection -LocalPort $port -State Listen).OwningProcess
$target = Get-Process -Id $target_pid
echo "Killing $target_pid $ $($target.MainModule.FileName)"
Stop-Process -Id $target_pid -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment