Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# ormaaj's init
\unalias -a
shopt -s lastpipe extglob expand_aliases
shopt -u assoc_expand_once
typeset -ga bool=([1]=)
function initializeBuiltins {
typeset -a a
@ormaaj
ormaaj / .bash
Last active November 3, 2022 05:43
#!/bin/bash
typeset -gx BASH_COMPAT=51
shopt -u assoc_expand_once
function assignArray {
typeset -n ref=$1 || return
shift
[[ ${ref@a} == *A* && "! ($# % 2)" -ne 0 ]] || return
typeset -A map
@ormaaj
ormaaj / .bash
Created October 1, 2022 09:06
flock search test
function initializeBuiltins {
local -
typeset -a a
typeset x y z
set +m
typeset libdir=${fsRoot%%+(/)}/usr/lib64
[[ -d ${libdir}/bash ]] || libdir=${rootPath%%+(/)}/lib64
for x in "${libdir}"/{ctypes.so,bash/!(hello|truefalse|mypid|necho|*.*)}; do
if [[ $(file -b --mime-type -- "$x") == 'application/x-sharedlib' && !$? -ne 0 ]]; then
@ormaaj
ormaaj / .bash
Last active September 23, 2022 16:12
builtin loader
shopt -s lastpipe extglob globstar
shopt -u assoc_expand_once
function initializeBuiltins {
typeset -a a
typeset x y z
set +m
typeset libdir=${fsRoot%%+(/)}/usr/lib64
[[ -d ${libdir}/bash ]] || libdir=${rootPath%%+(/)}/lib64
@ormaaj
ormaaj / .py
Created July 19, 2022 19:33
In _hash_filter._apply_hash_filter()
(ins)root@ormaaj-laptop (3852812) /home/ormaaj # PATH=$(readlink -sne ~ormaaj/doc/programs/portage/bin):${PATH##+(:)} PYTHONPATH=$(readlink -sne ~ormaaj/doc/programs/portage/lib):${PYTHONPATH##+(:)} NOLTO= NOGRAPHITE= NOGRAPHITE2= emerge -j 1 -bav dev-lang/python
These are the packages that would be merged, in order:
Calculating dependencies... done!
[ebuild R ] dev-lang/python [3.11.0_beta4-r2:3.11::gentoo] USE="bluetooth examples gdbm ncurses readline sqlite ssl -build -hardened -libedit -lto -pgo -test -tk -verify-sig -wininst" 0 KiB
Total: 1 package (1 reinstall), Size of downloads: 0 KiB
Would you like to merge these packages? [Yes/No]
@ormaaj
ormaaj / pattest.py
Last active July 9, 2022 17:31
Shell pattern quote/escape fuzzer.
#!/usr/bin/env python3
import subprocess, itertools
class Shell(list):
def __init__(self, shell, cmds):
self.shell = shell
super().__init__([(x, self.__run(x)) for x in cmds])
def __iter__(self):
@ormaaj
ormaaj / .bash
Created June 22, 2022 14:58
run gpg-agent
function setupGpgAgent {
# gpg-agent uses .gnupg but will not create the directory itself for new users.
if ! { [[ -d ~/.gnupg ]] || mkdir -p -- ~/.gnupg; }; then
printf 'bashrc: %s\n' 'No ~/.gnupg directory exists and failed to create it.' >&2
return 0
fi
if [[ -t 0 ]] && { GPG_TTY=$(readlink -sne /dev/fd/0) || GPG_TTY=$(tty); }; then
export GPG_TTY
else
@ormaaj
ormaaj / dircolors.bash
Created June 6, 2022 21:11
lol dircolors
function setupDirColors {
if [[ ${FUNCNAME[0]} == "${FUNCNAME[1]}" ]]; then
typeset -n LS_COLORS=$1
typeset dirc
if dirc=$("$(type -P dircolors 2>/dev/null)" -b); then
alias export=:; eval "$dirc"; unalias export
fi
else
typeset colors ret
if ! shopt -q expand_aliases; then
To hopefully add some insight, here's briefly my understanding of how
namerefs are supposed to work in these cases given the 3 implementations
I'm aware of.
Between ksh93, bash, and mksh, there are 3 different types of namerefs.
All three support "dynamic" namerefs, where each time a variable is
referenced, the shell looks at the currently visible variable whose name
is pointed to by the reference. All namerefs in bash and mksh are of
this type.
#!/bin/bash
if [[ ${KSH_VERSION+${!KSH_VERSION}} == .sh.version ]]; then
typeset -n FUNCNAME=.sh.fun
if builtin pids 2>/dev/null; then
function BASHPID.get { .sh.value=$(pids -f '%(pid)d'); }
elif [[ -r /proc/self/stat ]]; then
function BASHPID.get { read -r .sh.value _ </proc/self/stat; }
else