Skip to content

Instantly share code, notes, and snippets.

View ormaaj's full-sized avatar
🙃

Daniel Douglas ormaaj

🙃
View GitHub Profile
mkfs.vfat -F 32 --codepage=437 -n ESP -- "${d}1"
mkswap -L swap2 --verbose -- "${d}2"
mkfs.btrfs -vf -O extref,skinny-metadata,no-holes -R quota,free-space-tree --csum xxhash -L ormaaj2 -- "${d}3"
@ormaaj
ormaaj / sudoers
Created August 12, 2025 10:43
sudoers
# /etc/sudoers
Defaults !pam_session
Defaults !pam_setcred
Defaults !use_pty
Defaults fdexec
Defaults closefrom_override
Defaults targetpw
root ALL=(ALL:ALL) ALL
ALL ALL=(ALL:ALL) ALL
@ormaaj
ormaaj / .ps
Last active July 23, 2025 20:35
msys2 launcher
PowerShell 7.6.0-preview.4
Loading personal and system profiles took 2730ms.
PS C:\Users\ormaaj> Start-Process -Wait -NoNewWindow -Environment ([Environment]::GetEnvironmentVariables() + @{ MSYSTEM = 'UCRT64'; MSYS2_NOSTART = 'yes'; LOGINSHELL = 'bash'; TERM = 'xterm-direct' }) -FilePath 'C:\msys64\usr\bin\env.exe' -ArgumentList ([string[]]@('-S-- BASH_COMPAT=51 /c/Users/ormaaj/startdbus.bash /ucrt64/bin/konsole.exe'))
+ m /ucrt64/bin/konsole.exe
+ local -
+ [[ m != \m\a\i\n ]]
+ set +m
+ typeset -x BASH_COMPAT=51
+ m
+ local -
@ormaaj
ormaaj / argv0match.bash
Last active July 21, 2025 15:28
pgrep but better
shopt -s lastpipe
# return or write to stdout pids with argv[0]'s exactly matching any of the given arguments
# argv0match [ -v array ] names...
function argv0match {
local -; set +m
typeset OPTARG REPLY
typeset -i OPTIND=1
typeset -A opts
while getopts :zv: REPLY; do
@ormaaj
ormaaj / copy_array.bash
Last active September 5, 2025 19:01
bash array copy (without @k)
#!/usr/bin/env bash
shopt -s lastpipe extglob expand_aliases
function copy_array {
((1 + ${#} % 2)) || return
typeset k s r
typeset -a v=(src ret)
IFS= read -d '' s <<-\EOF
[ "${!r}" = "$1" ${| unset -n r; } ]; \
typeset -Gn r=${v[$?]} \
@ormaaj
ormaaj / roflparser.md
Created March 10, 2025 19:35
Silly bash typeset builtin wrapper

This script exploits bash's weird interpretation of POSIX's requirement that declaration builtins overloaded by functions must not modify the parsing of the arguments. Bash even extends this requirement to nonstandard extensions such as arrays. This typeset wrapper parses options by stealing the (approximately correct) optstring from ksh. It modifies each assignment then prints the effect of the command as a side-effect.

Code:

@ormaaj
ormaaj / .bash
Last active February 16, 2025 00:07
field splitting
for sh in bash bb dash yash gash bosh ksh kshv mksh loksh posh zsh mrsh; do
printf '%-6s ' "${sh}:"
"$sh" -c 'IFS=0; bash -c "printf \"%q \" \"\$@\"" bash $((x=1101001101))$((x))$((IFS=!IFS))${x}$((x)) ${x}$((x)) "${y:=$((x))}"${y+${z=$((y))}"$((y))"${z}$((IFS=!IFS))}' 2>&3
echo
done 3>/dev/null
@ormaaj
ormaaj / tmux.conf
Created January 29, 2025 23:13
tmux panes
%hidden trace='strace -DDYYyqqqf'
%hidden el=/usr/bin/execlineb
%hidden bashargs='-sipo vi +o posix +o histexpand -O lastpipe -O extglob -O expand_aliases +O array_expand_once +O sourcepath'
%hidden kshargs='-sipo vi -o posix'
%hidden shexec='import os, os.path, sys, pwd; \
os.sched_setscheduler(0, os.SCHED_OTHER, os.sched_param(0)); \
os.nice(-os.getpriority(os.PRIO_PROCESS, 0)); \
os.environ.setdefault("TMPDIR", "/tmp"); \
os.environ.setdefault("BASH_COMPAT", "51"); \
p = { k: str(v) for k, v in zip(("USER", None, "UID", "GID", None, "HOME", "SHELL"), pwd.getpwuid(os.geteuid())) if k }; \
@ormaaj
ormaaj / arr2set.bash
Last active August 26, 2024 18:08
multiple mixed type array to set
#!/usr/bin/env bash
BASH_COMPAT=51
# Swap or merge keys and indices
function arr2set {
typeset -i n m
typeset -n _ret=$1 r
[[ ${_ret@a} == *A* ]] || return
shift
for r do
@ormaaj
ormaaj / output (bash 5.3)
Last active August 16, 2024 19:04
test pipeline pid access through jobs -p
0: 0,4
1: 0,5
2: 0,6
3: 0,2