Skip to content

Instantly share code, notes, and snippets.

View ormaaj's full-sized avatar

Daniel Douglas ormaaj

View GitHub Profile
@ormaaj
ormaaj / ssh_config
Created February 3, 2026 12:00
openssh ProxyCommand for ProxyUseFdpass SCM_RIGHTS IPC
ProxyUseFdpass yes
ProxyCommand python3 -c 'import socket,sys,struct; s=socket.create_connection((sys.argv[1],int(sys.argv[2]))); socket.fromfd(1,socket.AF_UNIX,socket.SOCK_STREAM).sendmsg([b"\0"],[(socket.SOL_SOCKET,socket.SCM_RIGHTS,struct.pack("i",s.fileno()))])' %h %p
@ormaaj
ormaaj / pipe2.bash
Created February 3, 2026 08:47
Demonstrate a small optimization avoiding a pointless open().
ormaajbox /home/gentoo # ( echo; set +m; export BASH_COMPAT=50; { strace --always-show-pid --seccomp-bpf -DDYyyqqqe t=%desc bash -O lastpipe -O extglob "/proc/$((++BASH_COMPAT,BASHPID))/fd/9"; } 9<<-\_EOF 2> >(sed -E '/pipe2/q;d'; cat); wait )
x=<(:) x=${x##*/} command eval exec '{d[0]}<&"$x" {d[1]}>"/proc/self/fd/${x}"'
lsfd -p "$BASHPID" -Q "${| printf -v REPLY 'FD == %b || ' "${d[@]}\c"; }" -o +flags
:
_EOF
7135<bash> pipe2([3<pipe:[35912]>, 4<pipe:[35912]>], 0) = 0
7135<bash> fcntl(63<pipe:[37935]>, F_GETFD) = 0
7135<bash> fcntl(62, F_GETFD) = -1 EBADF (Bad file descriptor)
7135<bash> dup2(3<pipe:[35912]>, 62) = 62<pipe:[35912]>
@ormaaj
ormaaj / getparams.bash
Created December 6, 2025 05:43
nameref auto-mapper
#!/usr/bin/env bash
shopt -s lastpipe extglob expand_aliases
function unset2 {
unset -v "$@"
}
function getparams {
typeset -a v=v[l]=1+l,v
l=_[_=\${#v[@]}%\$#,0] let v
@ormaaj
ormaaj / fstabfmt.bash
Last active December 2, 2025 21:24
fstab generator
#!/usr/bin/env bash
shopt -s extglob lastpipe expand_aliases
typeset -Gx BASH_COMPAT=51
function fstabfmt {
local -; set +m
typeset x y IFS LC_CTYPE=C
typeset -a fields=(source target fstype options freq passno)
typeset -ia w=("${fields[@]/*/0}")
sendfile is not supported for transport <_UnixWritePipeTransport fd=7 idle bufsize=0>
Traceback (most recent call last):
File "/usr/bin/entry/entry_point", line 109, in _run_python
exec(code, exec_scope) # pylint: disable=exec-used
^^^^^^^^^^^^^^^^^^^^^^
File "<string>", line 187, in <module>
File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
@ormaaj
ormaaj / localopt.bash
Created October 29, 2025 12:57
simple shopt toggler
#!/usr/bin/env bash
shopt -s lastpipe extglob expand_aliases
function unset2 {
command unset "$@"
}
function localopt {
typeset IFS OPTARG REPLY r os=:v:uso
typeset -i i dn ret=0 OPTIND=1
@ormaaj
ormaaj / globsort.ksh
Created October 26, 2025 06:48
Numeric sort files matching a pattern (bash or ksh93)
if [[ -v KSH_VERSION ]]; then
typeset -n BASH_REMATCH=.sh.match
else
shopt -s extglob lastpipe
enable -f asort{,}
fi
touch file_{7..13}.pdf
unset -v a b
typeset -A a
@ormaaj
ormaaj / binutils
Last active September 30, 2025 21:25
ld xattr hooks
post_src_install() {
local -; set +o monitor -o pipefail
typeset k e r=${EROOT%%+(/)} cpn=${CATEGORY}/${PN}
e=${r:+${r}/}${ED%%+(/)}
typeset -A base=(
[sys-devel/binutils]=bfd
[sys-devel/mold]=mold
[llvm-core/lld]=lld
)
@ormaaj
ormaaj / tmux.conf
Created September 20, 2025 03:43
tmux.conf
# ~/.tmux.conf
if-shell \
'tput -T tmux-256color longname' \
'set -s default-terminal tmux-256color' \
'set -s default-terminal screen-256color'
%hidden trace='strace -DDYYyqqqf'
%hidden el=/usr/bin/execlineb
%hidden bash=/usr/bin/bash
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"