Skip to content

Instantly share code, notes, and snippets.

@gwennlbh
Last active January 29, 2026 13:42
Show Gist options
  • Select an option

  • Save gwennlbh/eb7613b3733b1d48c24fe632ed0c7f15 to your computer and use it in GitHub Desktop.

Select an option

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
Set-Alias ... cdup2
Set-Alias .. cdup
function cdup {
cd ..
}
function cdup2 {
cd ../..
}
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 ewen@gwen.works $args
}
function wait-until-pr-merged($number, $interval, $repo) {
if ($interval -eq $null) {
$interval = 10
}
echo "Checking every $interval seconds if PR #$number $(gh pr view $number --json title --jq .title) is merged"
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"
sleep 30
wait-until-run-finishes $workflow
return
}
$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 wait-until-job-finishes($run_id) {
$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) {
$conn = (Get-NetTCPConnection -LocalPort $port -State Listen)
if ($conn -Eq $null) {
echo "Nothing on :$port"
return
}
$target_pid = $conn.OwningProcess
$target = Get-Process -Id $target_pid
echo "Killing $target_pid $ $($target.MainModule.FileName)"
Stop-Process -Id $target_pid -Force
}
function merge-all-renovate-prs($query = "") {
foreach ($pr in gh search prs --owner gwennlbh --state open --author "renovate[bot]" --json number,repository --jq .[] $query) {
$number = echo $pr | jq .number
$repo = echo $pr | jq -r .repository.nameWithOwner
gh -R $repo pr merge --auto --squash $number
}
}
function gh-automerge {
gh pr merge --auto -mt "🔀 Merge '$( git rev-parse --abbrev-ref HEAD )' into main"
}
function paste {
get-clipboard
}
# Syntax highlighting colors
Set-PSReadLineOption -Colors @{
Command = 'Black'
Number = 'DarkGray'
Member = 'DarkGray'
Operator = 'DarkGray'
Type = 'DarkGray'
Variable = 'DarkGreen'
Parameter = 'DarkGreen'
ContinuationPrompt = 'DarkGray'
Default = 'DarkGray'
}
# Logging / Progress colors
$p = $host.privatedata
$p.ErrorForegroundColor = "Red"
$p.ErrorBackgroundColor = "White"
$p.WarningForegroundColor = "Yellow"
$p.WarningBackgroundColor = "White"
$p.DebugForegroundColor = "Yellow"
$p.DebugBackgroundColor = "White"
$p.VerboseForegroundColor = "Black"
$p.VerboseBackgroundColor = "White"
$p.ProgressForegroundColor = "DarkGray"
$p.ProgressBackgroundColor = "White"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment