Skip to content

Instantly share code, notes, and snippets.

@atomicstack
atomicstack / edit-path-interactively.sh
Created March 4, 2021 12:11
A shell function which spawns $EDITOR containing a $PATH declaration
function edit-path-interactively() {
eval "$( printf 'export PATH="%s"' "$PATH" | vipe )"
}
@atomicstack
atomicstack / generate_ssh_key_2021.sh
Created March 22, 2021 09:18
ssh-key creation helper, 2021
key_name="${USER}_$(hostname -s)_$(date +%F)"; echo "creating $HOME/.ssh/${key_name}.pem..."; ssh-keygen -t ed25519 -f "$HOME/.ssh/${key_name}.pem" -C "$key_name"
@atomicstack
atomicstack / rpi_temperature-config.txt
Created May 31, 2021 22:37
a more sensible and less noisy fan config for raspberry pis with the poe hat.
dtoverlay=rpi-poe
dtparam=poe_fan_temp0=62000
dtparam=poe_fan_temp1=64000
dtparam=poe_fan_temp2=66000
dtparam=poe_fan_temp3=68000
@atomicstack
atomicstack / .Xdefaults
Last active June 1, 2021 19:50
make XQuartz's xterm less fugly
# xterm args:
# xterm -fg white -bg black -en utf8 -tn xterm-256color -fa inputmono:size=14 -fn inputmono:size=14 -geometry 90x30
# see also:
# https://web.archive.org/web/20100616023737/http://yarger.asu.edu/NMR/Xdefaults.html
# https://gist.github.com/tshanks/1145068/e04565f405098193f3fe79b123fa805d0102a5ab
# https://unix.stackexchange.com/questions/332316/configure-unreadable-tiny-small-huge-xterm-fonts
# man xterm
xterm*faceName:inputmono:style=Regular:size=14
@atomicstack
atomicstack / ssh_warning.sh
Created June 2, 2021 21:37
a zsh thing to run at login time and check whether the user has an ssh-agent
red=$(tput setaf 1)
reset=$(tput sgr0)
if [[ -n "${SSH_TTY}" || -n "${TTY}" ]]; then
if [[ $UID == 0 ]]; then
return
fi
if [[ -z "$SSH_AUTH_SOCK" || ! -S "$SSH_AUTH_SOCK" ]]; then
echo -e "${red}no ssh-agent found :(${reset}"
elif ssh-add -l | grep -q "no identities"; then
@atomicstack
atomicstack / backup_zsh_history.sh
Last active June 4, 2021 12:21
back up my zsh history (via crontab) (double check paths before use!)
/bin/cat $HOME/.zsh_history | /usr/local/bin/xz > $HOME/.zsh_history.d/zsh_history.$(/usr/local/bin/gdate +%F-%T).xz
@atomicstack
atomicstack / cleanup_zsh_history_archive.sh
Created June 4, 2021 12:20
cleans up duplicate zsh_history files from $PWD (double check paths before use!)
ls | egrep --line-buffered 'zsh_history.*xz$' | xargs sha256sum | pv -l -s $( ls | egrep --line-buffered 'zsh_history.*xz$' | wc -l | xargs ) | /usr/local/bin/sponge | perl -naE '$seen{$F[0]}++ or next; unlink $F[1] and say qq{unlinked $F[1]}'
@atomicstack
atomicstack / root_ps1.zsh
Created June 14, 2021 12:11
zsh root PS1
export PS1='%F{226}%m%f %F{33}%d%f %F{160}%#%f '
@atomicstack
atomicstack / ssh_config
Last active June 15, 2021 11:44
example Match stanza for ssh_config, which executes echo "hello world" before connecting to a (specific) host as a specific username. note: redirection to STDERR is necessary; using STDOUT will result in no output
Match host $HOSTNAME exec "echo 'hello world' 1>&2"
User $USERNAME
@atomicstack
atomicstack / prune-invalid-git-refs.sh
Created July 19, 2021 13:24
fixes annoying "error: refs/remotes/origin/${branch_name} does not point to a valid object!"
#!/bin/bash
git for-each-ref --format="%(refname)" | while read ref; do
git show-ref --quiet --verify $ref 2>/dev/null || git update-ref -d $ref
done