Skip to content

Instantly share code, notes, and snippets.

@spmason
spmason / k9
Created September 12, 2023 15:43
Kubernetes helper scripts
#!/bin/bash
#
# A generic command that makes it easy to run k9s against a specific cluster
# - without messing around with contexts (like kubectx does), eg:
#
# $ k9 prod-cluster get pods
#
# See the `kube` script alongside this one for more info (it's exactly the same except the final command is different)
#
set -ue -o pipefail
@spmason
spmason / dependabump
Created December 15, 2021 10:45
Create an octopus-merge of all pending dependabot PRs that are passing CI
#!/usr/bin/env bash
git co -b dependabot-$(date '+%Y-%m-%d') && \
gh pr list --label dependencies --json number,headRefName --search 'status:success' --jq '.[].headRefName | "origin/\(.)"' \
| xargs git merge && \
pr
@spmason
spmason / kube
Created December 15, 2021 10:42
Command for working with k8s contexts without needing to use kubectx or similar
#!/bin/bash
set -ue -o pipefail
CLUSTER=$1
shift
CLUSTER_KUBECONFIG="$HOME/.kube/config.${CLUSTER}"
if ! [ -f $CLUSTER_KUBECONFIG ]; then
echo "current-context: ${CLUSTER}" > $CLUSTER_KUBECONFIG

Keybase proof

I hereby claim:

  • I am spmason on github.
  • I am spmason (https://keybase.io/spmason) on keybase.
  • I have a public key ASAceBYevAn4wzt1xOUf4yh78gRqksgRkZl5ZdGwl1Qgugo

To claim this, I am signing this object:

@spmason
spmason / "git pr" alias
Last active September 22, 2023 08:41
Checkout PRs. I'm not sure where I got this from but I can't take credit for it
# Checks out a PR to a pr/<number> local branch
# Usage: git pr <number> [<upstream>]
git config --global alias.pr '!git fetch -fu ${2:-upstream} refs/pull/$1/head:pr/$1 && git checkout pr/$1 && :'
# Deletes pr/<number> branches
# Usage: git pr-clean
git config --global alias.pr-clean '!git for-each-ref refs/heads/pr/* --format='"'"'%(refname)'"'"' | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done'
@spmason
spmason / pr
Last active July 15, 2022 10:54
GitHub "open PR" script. Add somewhere in your path, then opening a PR is as easy as typing `pr` on the branch you want to open a PR for
#!/usr/bin/env bash
# GitHub "Open Pull Request" script
#
# Add somewhere in your path, then opening a PR is as easy as typing `pr` while you're
# on the branch you want to open a Pull Request for
#
# NOTES:
# - Uses the `hub` tool: https://cli.github.com/
# - Assumes that the upstream repository is called 'origin' and your fork is named after your github username