Skip to content

Instantly share code, notes, and snippets.

@gwennlbh
Last active July 14, 2026 10:20
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
}
function updateprofile {
gh gist view eb7613b3733b1d48c24fe632ed0c7f15 --raw > $profile
. $profile
}
# 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) {
if ($number -eq $null) {
$number = (gh pr view --json number --jq .number)
}
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) {
$encodingArg = if ([int](Get-Host).Version.Major -gt 5) {@{AsByteStream = $true}} else {@{Encoding = "Byte"}}
$contentBytes = Get-Content $file -Raw @encodingArg
$base64 = [Convert]::ToBase64String($contentBytes)
Set-Clipboard -Value ($base64).ToString()
echo ($base64).ToString()
}
function base64-decode-file($encodedFile, $destination) {
[IO.File]::WriteAllBytes($destination, [Convert]::FromBase64String([char[]][IO.File]::ReadAllBytes($encodedFile)))
}
function wait-until-run-finishes {
param (
[Parameter(Mandatory=$true)]
[ArgumentCompleter({ ls .github/workflows | ForEach-Object { $_.name } })]
$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
$status = $(gh run view $run_id --json status --jq .status)
while ( ($status -eq "in_progress") -or ($status -eq "queued") ) {
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"
function retry-workflow($workflow_file, $num = 0) {
if ($num -eq 0) {
$workflow_number = ((gh run list -w $workflow_file | fzf) -Split "\t")[-3]
} else {
$workflow_number = $num
}
gh run rerun --failed $workflow_number
}
function retry-workflow-like-a-dumbahh($workflow_file, $num = 0) {
if ($num -eq 0) {
$workflow_number = ((gh run list -w $workflow_file | fzf) -Split "\t")[-3]
} else {
$workflow_number = $num
}
while ((gh run view $workflow_number --json status --jq '.status == "in_progress" or .status == "queued"') -eq "true") {
gum log -t timeonly -s -l debug "still in progress…" number $workflow_number file $workflow_file
sleep 300
}
$conclusion = $(gh run view $workflow_number --json conclusion --jq .conclusion)
if ($conclusion -eq "success") {
echo "okay :)"
} else {
gum log -t timeonly -s -l debug "retrying" conclusion "$conclusion" number $workflow_number file $workflow_file
gh run rerun --failed $workflow_number
retry-workflow-like-a-dumbahh $workflow_file $workflow_number
}
}
function disable-touchscreen {
gsudo {
Get-PnpDevice | Where-Object {$_.FriendlyName -like '*touch screen*'} | Disable-PnpDevice -Confirm:$false
}
}
function enable-touchscreen {
gsudo {
Get-PnpDevice | Where-Object {$_.FriendlyName -like '*touch screen*'} | Enable-PnpDevice -Confirm:$false
}
}
function which {
get-command $args
}
function withenv {
start-process -Environment $args[0] $args[1..$args.count]
}
function renovate {
$dashboard_issue = $(gh issue list -S "author:renovate[bot]" --json number,title --jq '.[]|select(.title == "Dependency Dashboard").number')
gh browse $dashboard_issue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment