Skip to content

Instantly share code, notes, and snippets.

@sepen
sepen / gitme.sh
Last active July 10, 2025 08:32
Show differences for git repositories
#!/bin/bash
# do not use locales
export LC_ALL=C
# tmp dir
readonly GITME_TMPDIR="$HOME/.gitme/tmp"
mkdir -p $GITME_TMPDIR >/dev/null 2>&1
# top dir from environment variable
@sepen
sepen / mac-install-kext.sh
Created November 2, 2024 00:32
Install macOS Kernel extension files
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
cat << __EOF__
Usage: $(basename $0) KEXT_FILE
__EOF__
exit 0
fi
echo "Installing $1"
@sepen
sepen / ssh-legacy-dss.sh
Created November 2, 2024 00:27
OpenSSH client wrapper to use the ssh-dss (DSA) public key algorithm
#!/usr/bin/env bash
# OpenSSH 7.0 and greater similarly disable the ssh-dss (DSA) public key algorithm.
# It too is weak and we recommend against its use.
# It can be re-enabled using the HostKeyAlgorithms configuration option:
#  ssh -oHostKeyAlgorithms=+ssh-dss user@legacyhost
# or in the ~/.ssh/config file:
# Host somehost.example.org
# HostKeyAlgorithms +ssh-dss
# http://www.openssh.com/legacy.html
@sepen
sepen / git-delete-local-merged-branches.sh
Created November 2, 2024 00:20
Cleanup local git branches that are already merged into master or main
#!/usr/bin/env bash
# Delete all local branches that are already merged into master or main
git branch --merged master | grep -v '^[ *]*master$' | xargs git branch -d
git branch --merged main | grep -v '^[ *]*main$' | xargs git branch -d
# End of file
@sepen
sepen / git-rename-master-to-main.sh
Created November 2, 2024 00:16
Rename master branch to main in a git repository
#!/usr/bin/env bash
echo "Rename git branch master -> main"
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
# End of file
@sepen
sepen / git-show-old-branches.sh
Created November 2, 2024 00:13
Print merged branches in a git repository
#!/usr/bin/env bash
git branch -v --sort=-committerdate --remote --merged \
| grep -ve 'origin/main' -ve 'origin/master' -ve 'origin/HEAD' \
| xargs -L1
# remove to keep only 10 lines
#| sed 1,10d | tac
# End of file
@sepen
sepen / git-cleanup-old-merged-branches.sh
Created November 2, 2024 00:08
Cleanup old merged branches in a git repository
#!/usr/bin/env bash
DRY_RUN=0
case $1 in
# --dry-run
# Show what would be done, without making any changes
--dry-run) DRY_RUN=1 ;;
esac
@sepen
sepen / mac-fix-non-breaking-space.sh
Last active November 2, 2024 00:05
Map keybindings Option-Space to regular space
#!/usr/bin/env bash
mkdir -p ~/Library/KeyBindings
cat >> ~/Library/KeyBindings/DefaultKeyBinding.dict << __EOF__
{
"~ " = ("insertText:", " ");
}
__EOF__
@sepen
sepen / kernel-set-cpu-governor.sh
Created November 1, 2024 21:33
Setup scaling governor for Linux kernel
#!/usr/bin/env bash
# Documentation of CPU governors
# http://www.kernel.org/doc/Documentation/cpu-freq/governors.txt
[ $# -lt 1 ] && (
echo "Usage: $(basename $0) [performance|powersave|userspace|ondemand|conservative]"
exit 0
)
@sepen
sepen / snap-cleanup.sh
Created November 1, 2024 21:28
Cleanup old revisions of snap installed packages
#!/usr/bin/env bash
read -p "WARNING: Close all snaps before running this. Continue? [y|N] " ans
[ "$ans" != "y" ] && exit 1
export LANG=en_US.UTF-8
set -eu
# Set the maximum number of snap revisions stored for each package.
# It can only be a number between 2 and 20 and has a default value of 3.