Skip to content

Instantly share code, notes, and snippets.

View taikedz's full-sized avatar

Tai Kedzierski taikedz

View GitHub Profile
@taikedz
taikedz / docker-shell.sh
Last active June 27, 2018 10:50
Run a shell inside a shell-less docker image (Ubuntu host, ephemeral container)
#!/bin/bash
# ++++++++++++++++++++++
die() {
echo -e "\033[31;1m$*\033[0m"
exit 1
}
# ++++++++++++++++++++++
@taikedz
taikedz / ubin
Last active July 10, 2018 10:59
Run an X application as a different user, with some sound working
#!/usr/bin/env bash
die() {
echo "$*"
exit 1
}
turnoff_xhost() {
xhost - >/dev/null 2>&1
}
@taikedz
taikedz / reset-inode-order.sh
Last active July 16, 2018 10:12
Ensure inodes of files in a folder are in the same order as the filename order. Because my Aygo x-Play's USB reader sorts by inode. Wtf.
#!/usr/bin/env bash
deepset() {
find . -type d -exec bash "$0" {} \;
}
hasmp3() {
ls *.mp3 >/dev/null 2>&1
}
@taikedz
taikedz / git-squash-intermediates.md
Last active July 24, 2018 16:07
Squash intermediate git commits (and a cherry-picking shorthand)

Squashing intermediate commits, cherry-picking

You cannot directly squash earlier commits whilst retaining later ones.

Instead you need to create a picking branch, do some reset operations, re-commit the intermediary changes, and cherry-pick over the relevant commits. You must start from a clean state - no modifications, no staged items, no untracked files. Working tree clean must appear in your git status.

Below, my-branch-name is the name of the branch you are on.

@taikedz
taikedz / root_folder_sizes.sh
Created July 26, 2018 09:02
Sizes in root folder
folders=()
while read f; do
folders+=("/$f")
done < <(ls /|grep -v -P 'run|dev|proc')
sudo du -sh "${folders[@]}"|sort -h
@taikedz
taikedz / passcrypt.sh
Last active October 18, 2018 16:17
Decrypt a symmetric password encrypted string using openssl, and put it in the x-clipboard (`shift + insert` to paste) uing xclip
# Example to create an encrypted string:
# echo "hi"|openssl aes-256-cbc -a
# the decryption example below is for password "pass"
# requires openssl and xclip
give-my-token() {
# Using 1.1.0+
echo "U2FsdGVkX1/uwQA5Uc/F8vTYJEWZcgcuY+V9DVQovNs="|openssl aes-256-cbc -a -d 2>/dev/null|xclip || {
@taikedz
taikedz / resetup.sh
Last active August 23, 2018 11:24
Initial setup script
# You can copy/paste this to a terminal
# No stdin swallowing issues, no working dir displacement
install-my-tools() {
# Try to run something, offer the user a way to resolve problems and retry
try-to() {
local result
echo -e "\033[31;1m$*\033[0m"
while ! (set -e; "$@"); do
espeak 'Error" executing command' # the " is audible punctuation
@taikedz
taikedz / mvgit.source
Created September 6, 2018 12:01
Move git from one folder to another, and update its remote url
#!/usr/bin/env bash
mvgit() {
( set -x
[[ -d "$1" ]] &&
(
mkdir -p "$(dirname "$2")"
mv "$1" "$2"
)
[[ -n "$3" ]] &&
@taikedz
taikedz / reconcile-swap.sh
Created September 11, 2018 14:48
Find temporary vim swp files, load in new session; on exiting vim, prompt for deletion of swap file
#!/usr/bin/env bash
cred="$(echo -e '\033[31;1m')"
cgrn="$(echo -e '\033[32;1m')"
cyel="$(echo -e '\033[33;1m')"
cblu="$(echo -e '\033[34;1m')"
cdef="$(echo -e '\033[0;m')"
do_reconcile() {
swapfile="$1"; shift
@taikedz
taikedz / copyto.sh
Last active September 30, 2018 20:25
Copy music files, in alphabetical order, to a new directory, converting non-mp3 files along the way
#!/bin/bash
set -euo pipefail
audio_file_extensions=(mp3 mp4 ogg oga ogv opus 3ga wav mka aiff mpeg mpg m4a wma wmv flac)
act() {
if [[ "${APPLY:-}" = true ]]; then
( set -x
# We don't want this command consuming the parent stdin