Skip to content

Instantly share code, notes, and snippets.

@aaronNGi
aaronNGi / clonevm.ps1
Created October 14, 2022 10:35
Script for easy cloning of MS Hyper-V VMs
# Creates clones of HyperV virtual machines
# Author: Aaron Gießelmann
# Date: 22-10-14
function die {
$_.Exception
exitwait 1
}
function exitwait {
@aaronNGi
aaronNGi / wordle.bash
Last active February 22, 2022 17:31
Wordle in 20 lines of bash
#!/usr/bin/env bash
mapfile -t words < <(grep -x '[a-z]\{5\}' "${WORDLIST:-/usr/share/dict/words}")
word=${words[RANDOM % ${#words[@]}]} pool=abcdefghijklmnopqrstuvwxyz
for ((round=1; round <= ${ROUNDS:=6}; round++)); do
while read -rp "$round/$ROUNDS: " guess || exit 1; do
[[ " ${words[@]} " == *" ${guess,,} "* ]] && guess=${guess,,} && break
done
for ((i=0, chars=0; i < ${#word}; i++)); do
[[ ${word:i:1} != ${guess:i:1} ]] && chars+=${word:i:1}
done
@aaronNGi
aaronNGi / redraw.sh
Created January 31, 2021 15:18
Small utilities to draw a stopwatch as seven-segment display to the terminal. Usage: timer.sh | redraw.sh | segments.awk
#!/bin/sh
esc() {
printf '\033%s' "$@" >&2
}
clean_exit() {
_exit_status=$?
trap - EXIT
# Show cursor again.
@aaronNGi
aaronNGi / statusbar.sh
Created January 29, 2021 09:54
A portable statusbar script which can update its components at different time intervals, using minimal sub-processes
#!/bin/sh
set -ef
main() {
trap 'kill 0' EXIT HUP INT
emitter | collector
}
# All variables used here are dynamically assigned via `export`.
@aaronNGi
aaronNGi / newscript.sh
Created April 28, 2020 20:38
Boilerplate for new POSIX shell scripts
#!/bin/sh
prog_name=${0##*/}
version=1.0
version_text="Boilerplate for new scripts v$version"
options="h o: q v V"
help_text="Usage: $prog_name [-o <text>] [-hqvV] [<file>]...
Boilerplate for new scripts