Skip to content

Instantly share code, notes, and snippets.

@putnamhill
putnamhill / bash-snippets.md
Last active March 8, 2024 14:17
bash snippets - these are notes for myself; some found and some I've made

git

get the last commit hash in abbreviated form

 git log -n1 --pretty=format:%h

list files in another branch

git ls-files --with-tree=another-branch
@putnamhill
putnamhill / hdiutil-attach-detach.sh
Last active January 25, 2024 22:16
Steps to attach a dmg disk image using hdiutil while capturing the mount point and dev entry for detaching when done
#!/bin/bash
dmg_path="$1"
# use process redirection to capture the mount point and dev entry
IFS=$'\n' read -rd '\n' mount_point dev_entry < <(
# mount the diskimage (leave out -readonly if making changes to the file system)
hdiutil attach -readonly -plist "$dmg_path" | \
@putnamhill
putnamhill / docker-rmi-interactive.sh
Last active January 4, 2024 13:40
A script to help clean up docker images interactively
#!/bin/bash
agree() {
local question="$1"
while true; do
read -p "$question " answer
case $answer in
[Yy]|[Yy][Ee][Ss]) return 0 ;;
[Nn]|[Nn][Oo]|'') return 1 ;; # empty string is default
#!/bin/sh
# create remote origin and push
# use 'trunk' unless init.defaultBranch is set
default_branch=$(git config init.defaultBranch || echo 'trunk')
remote_host='your-remote-host'
# assuming the remote host has a directory in $HOME named git
toplevel=$(git rev-parse --show-toplevel)
remote_repo_path="git/${toplevel##*/}.git"
@putnamhill
putnamhill / README.md
Last active February 3, 2023 21:51
parse firewall rules with xslt

parse firewall rules with xslt

to run

xsltproc firewall.xsl source.xml

to test with bash

diff --report-identical-files &lt;(xsltproc firewall.xsl source.xml) expect
#!/usr/bin/env bash
split() {
local IFS="$1"
shift
set -- $*
echo "$@"
}
join() {

nginx snippets

internal redirects

../test-internal-redirects.conf

location = /real1 { try_files /real1.txt =404; }
location = /real2 { try_files /real2.txt =404; }
@putnamhill
putnamhill / group-dupes.pl
Last active June 19, 2021 14:16
Print groups of files that are duplicates.
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Digest::MD5;
#use diagnostics;
my $minimum = 0;
my $header = '';

Git current branch

The shell used in the following examples is bash, but the commands can be adapted for other shells.

reading it

Determine if working in a git repository

The goal here is to have a performant way to determine if we are in a git repo without printing anything.

git status --porcelain --untracked-files=no &amp;&gt;/dev/null &amp;&amp; \
@putnamhill
putnamhill / ics2stdout.awk
Created February 23, 2019 23:03
an awk script to convert Apple's reminder lists to plain text
#!/usr/bin/env awk -f
BEGIN {
FS = ":"
RS = "\r\n"
OFS = "\t"
}
/BEGIN:VTODO/ {
my_status = ""