Skip to content

Instantly share code, notes, and snippets.


Erik Westrup erikw

View GitHub Profile
erikw /
Created Apr 25, 2021 — forked from jamesmacfie/
iTerm 2 - script to change theme depending on Mac OS dark mode

How to use

In iTerm2, in the menu bar go to Scripts > Manage > New Python Script

Select Basic. Select Long-Running Daemon

Give the script a decent name (I chose

Save and open the script in your editor of choice.


Keybase proof

I hereby claim:

  • I am erikw on github.
  • I am erikwestrup ( on keybase.
  • I have a public key whose fingerprint is D5EF DF01 3574 AE9B E834 3C32 7C16 B114 8E43 2F36

To claim this, I am signing this object:

erikw / znp
Last active Oct 23, 2020
znp: Wrap shell command in ZFS pre-post snapshots and log outputs.
View znp
#!/usr/bin/env bash
# Runs a command wrapped in ZFS pre-post snapshots. The whole data pool is recursively snapshotted.
# Analogous to my snp script for BTRFS:
# Usage: $ znp <commands>
# e.g.: $ znp pgk upgrade
# e.g.: $ znp portmaster -aG
# e.g.: $ znp freebsd-upgrade install
erikw /
Last active Mar 26, 2018 interactively upgrade all local brew & cask packages for macOS
#!/usr/bin/env bash
# Interactively upgrade my homebrew system.
# Usage:
# Requirements:
# - Install cask upgrade command with: $ brew tap buo/cask-upgrade
# Exit script on SIGINT.
set -e
CLI_PREFIX="📦$(tput setaf 1) ======>$(tput sgr0)"
View restic-backup.service
erikw / snp
Last active Apr 28, 2021
snp: Wrap shell command in BTRFS snapper pre-post snapshots and log outputs.
View snp
#!/usr/bin/env bash
# Runs a command wrapped in btrfs snapper pre-post snapshots.
# Usage: $ snp <commands>
# e.g.: $ snp pacman -Syyu
# The latest version of this script is hosted at
date=$(date "+%Y-%m-%d-%H%M%S")
#!/usr/bin/env bash
trim_method="roll" # Can be {trim or roll).
max_len=30 # Trim output to this length.
roll_speed=2 # Roll speed in chraacters per second.
segment_path=$(dirname $0)
source "$segment_path/../"
np="A pretty long line for a song title eh?"
np=$(roll_text "${np}" ${max_len} ${roll_speed})
erikw /
Created May 23, 2012
Bash ANSI colors
# Source this file where ANSI colors are needed. Colors in strings should be quoted with "" and echos needs to interpret backslash (echo -e).
# Reference:
function export_colors() {
# ANSI colors codes.
local DULL=0
local BRIGHT=1
local FG_NULL=00
local FG_BLACK=30
erikw /
Created Feb 24, 2012
NP from mpd in KDE
# Announce current song playing in mpd in a KDE notification.
# Icon support for passivepopup is implemented in more recent versions of KDE.
#path=`mpc -f %file% | head -n1 | sed 's/\(.*\)\/.*\..\+$/~\/mult\/music\/\1/'`
#icon=`find $path -type f -iregex '.*\.\(png\|jpg\|jpeg\|gif\|bmp\)$' -print | head -n1`
#kdialog --icon "$icon" --title "Currently playing song" --passivepopup "$np" 3
#np=`mpc --format "%title%[\n%album%]\n%artist%" | head -n3`
np=`mpc --format "%title%[\n%album%]\n%artist%" | grep -Pzo '^(.|\n)*?(?=\[)'`
erikw / toggle_spell.vim
Created Jan 25, 2012
Toggle spellang in Vim.
View toggle_spell.vim
" Toggle spell with a language. {{{
function! ToggleSpell(lang)
if !exists("b:old_spelllang")
let b:old_spelllang = &spelllang
let b:old_spellfile = &spellfile
let b:old_dictionary = &dictionary
let l:newMode = ""
if !&l:spell || a:lang != &l:spelllang