Monday, November 2, 2026

this no one will understand i promise

 #!/usr/bin/env bash

# pyreg.sh: registry-style store in pure bash.
#
# Here the directory tree IS the registry: keys are directories under
# ~/pyreg/ and values are files, so ls/cat/grep work on it directly.
#
# Usage:
# pyreg.sh set <key> <name> <value>
# pyreg.sh setfile <key> <name> <file>
# pyreg.sh get <key> <name>
# pyreg.sh run <key> <name> run a stored script (.py .pl .sh)
# pyreg.sh list
set -euo pipefail

ROOT="${PYREG_ROOT:-$HOME/pyreg}"

die() { echo "$*" >&2; exit 1; }

# HKEY_CURRENT_USER\Software\App -> $ROOT/HKEY_CURRENT_USER/Software/App
key_dir() {
local key="${1//\\//}" part out="$ROOT"
local IFS=/
for part in $key; do
[[ -z "$part" ]] && continue
[[ "$part" == "." || "$part" == ".." ]] && die "invalid key"
out+="/$part"
done
printf '%s' "$out"
}

value_path() {
[[ "$2" == */* || "$2" == "." || "$2" == ".." || -z "$2" ]] && die "invalid value name"
printf '%s/%s' "$(key_dir "$1")" "$2"
}

cmd="${1:-}"
[[ -z "$cmd" ]] && { sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//'; exit 0; }
shift

case "$cmd" in
set)
[[ $# -eq 3 ]] || die "usage: set <key> <name> <value>"
p="$(value_path "$1" "$2")"
mkdir -p "$(dirname "$p")"
printf '%s' "$3" > "$p"
[[ "$2" =~ \.(py|pl|sh)$ ]] && chmod 755 "$p"
echo "stored $p"
;;
setfile)
[[ $# -eq 3 ]] || die "usage: setfile <key> <name> <file>"
[[ -r "$3" ]] || die "cannot read $3"
p="$(value_path "$1" "$2")"
mkdir -p "$(dirname "$p")"
cp "$3" "$p"
[[ "$2" =~ \.(py|pl|sh)$ ]] && chmod 755 "$p"
echo "stored $p"
;;
get)
[[ $# -eq 2 ]] || die "usage: get <key> <name>"
p="$(value_path "$1" "$2")"
[[ -f "$p" ]] && cat "$p" || true
echo
;;
run)
[[ $# -eq 2 ]] || die "usage: run <key> <name>"
p="$(value_path "$1" "$2")"
[[ -f "$p" ]] || die "no such value"
case "$2" in
*.py) exec python3 "$p" ;;
*.pl) exec perl "$p" ;;
*.sh) exec bash "$p" ;;
*) die "don't know how to run '$2'" ;;
esac
;;
list)
[[ -d "$ROOT" ]] || exit 0
(cd "$ROOT" && find . -type f | sed 's|^\./||' | sort)
;;
*)
die "unknown command '$cmd'"
;;
esac

this no one will understand

#!/usr/bin/env perl
# pyreg.pl: registry-style store that appears as a Unix directory tree (Perl version).
#
# Keys look like HKEY_CURRENT_USER\Software\MyApp and hold named values.
# The store lives in ~/.pyreg.json and is materialised as files under ~/pyreg/.
#
# Usage:
#   pyreg.pl set     <key> <name> <value>
#   pyreg.pl setfile <key> <name> <file>    store a script's source as a value
#   pyreg.pl get     <key> <name>
#   pyreg.pl run     <key> <name>           run a stored script (.py .pl .sh)
#   pyreg.pl list
#   pyreg.pl mount
use strict;
use warnings;
use JSON::PP;
use File::Path qw(make_path);
use File::Spec;
use File::Temp qw(tempfile);

my $home  = $ENV{HOME} or die "HOME not set\n";
my $store = "$home/.pyreg.json";
my $mount = "$home/pyreg";
my $json  = JSON::PP->new->canonical->pretty;

sub load {
    return {} unless -e $store;
    open my $fh, '<', $store or die "cannot read $store: $!\n";
    local $/;
    my $data = <$fh>;
    close $fh;
    return decode_json($data);
}

sub save {
    my ($reg) = @_;
    open my $fh, '>', $store or die "cannot write $store: $!\n";
    print $fh $json->encode($reg);
    close $fh;
}

sub key_path {
    my ($key) = @_;
    (my $k = $key) =~ s{/}{\\}g;
    my @parts = grep { length } split /\\/, $k;
    die "invalid key\n" if grep { $_ eq '..' || $_ eq '.' } @parts;
    return File::Spec->catdir(@parts);
}

sub do_mount {
    my ($reg) = @_;
    make_path($mount);
    for my $key (sort keys %$reg) {
        my $dir = File::Spec->catdir($mount, key_path($key));
        make_path($dir);
        for my $name (sort keys %{ $reg->{$key} }) {
            next if $name =~ m{/} || $name eq '.' || $name eq '..';
            my $path = "$dir/$name";
            open my $fh, '>', $path or die "cannot write $path: $!\n";
            print $fh $reg->{$key}{$name};
            close $fh;
            chmod 0755, $path if $name =~ /\.(py|pl|sh)$/;
        }
    }
    print "mounted at $mount\n";
}

my ($cmd, @a) = @ARGV;
unless (defined $cmd) { print "usage: $0 set|setfile|get|run|list|mount ...\n"; exit 0; }
my $reg = load();

if ($cmd eq 'set' && @a == 3) {
    $reg->{ $a[0] }{ $a[1] } = $a[2];
    save($reg);
    do_mount($reg);
}
elsif ($cmd eq 'setfile' && @a == 3) {
    open my $fh, '<', $a[2] or die "cannot read $a[2]: $!\n";
    local $/;
    $reg->{ $a[0] }{ $a[1] } = <$fh>;
    close $fh;
    save($reg);
    do_mount($reg);
}
elsif ($cmd eq 'get' && @a == 2) {
    print $reg->{ $a[0] }{ $a[1] } // '', "\n";
}
elsif ($cmd eq 'run' && @a == 2) {
    my $src = $reg->{ $a[0] }{ $a[1] };
    die "no such value\n" unless defined $src;
    my %interp = (py => 'python3', pl => 'perl', sh => 'bash');
    my ($ext) = $a[1] =~ /\.(\w+)$/;
    my $prog = $interp{ $ext // '' } or die "don't know how to run '$a[1]'\n";
    my ($fh, $tmp) = tempfile(SUFFIX => ".$ext", UNLINK => 1);
    print $fh $src;
    close $fh;
    system($prog, $tmp);
    exit($? >> 8);
}
elsif ($cmd eq 'list') {
    print $json->encode($reg);
}
elsif ($cmd eq 'mount') {
    do_mount($reg);
}
else {
    die "bad arguments; run with no arguments for usage\n";
}

Holy motherfuck

 #!/usr/bin/env python3

"""pyreg: a tiny Windows-registry-style store that shows up as a Unix directory tree.


Keys look like HKEY_CURRENT_USER\\Software\\MyApp and hold named values.

The store lives in ~/.pyreg.json and is "mounted" (materialised) as plain

files under ~/pyreg/, so bash can browse it with ls/cat.


Usage:

  pyreg.py set  <key> <name> <value>      store a value

  pyreg.py setpy <key> <name> <file.py>   store a Python script's source as a value

  pyreg.py get  <key> <name>              print a value

  pyreg.py run  <key> <name>              execute a stored script

  pyreg.py list                           show the whole registry

  pyreg.py mount                          write the tree to ~/pyreg/

"""

import json

import os

import subprocess

import sys

import tempfile


STORE = os.path.expanduser("~/.pyreg.json")

MOUNT = os.path.expanduser("~/pyreg")



def load():

    try:

        with open(STORE) as f:

            return json.load(f)

    except FileNotFoundError:

        return {}



def save(reg):

    with open(STORE, "w") as f:

        json.dump(reg, f, indent=2)



def key_path(key):

    # HKEY_CURRENT_USER\Software\App -> HKEY_CURRENT_USER/Software/App

    parts = [p for p in key.replace("/", "\\").split("\\") if p]

    if ".." in parts:

        sys.exit("invalid key")

    return os.path.join(*parts) if parts else ""



def mount(reg):

    os.makedirs(MOUNT, exist_ok=True)

    for key, values in reg.items():

        d = os.path.join(MOUNT, key_path(key))

        os.makedirs(d, exist_ok=True)

        for name, val in values.items():

            if "/" in name or name in ("..", "."):

                continue

            p = os.path.join(d, name)

            with open(p, "w") as f:

                f.write(val)

            if name.endswith(".py"):

                os.chmod(p, 0o755)

    print(f"mounted at {MOUNT}")



def main(argv):

    if len(argv) < 2:

        print(__doc__)

        return

    cmd, reg = argv[1], load()

    if cmd == "set" and len(argv) == 5:

        reg.setdefault(argv[2], {})[argv[3]] = argv[4]

        save(reg)

        mount(reg)

    elif cmd == "setpy" and len(argv) == 5:

        with open(argv[4]) as f:

            reg.setdefault(argv[2], {})[argv[3]] = f.read()

        save(reg)

        mount(reg)

    elif cmd == "get" and len(argv) == 4:

        print(reg.get(argv[2], {}).get(argv[3], ""))

    elif cmd == "run" and len(argv) == 4:

        src = reg.get(argv[2], {}).get(argv[3])

        if src is None:

            sys.exit("no such value")

        with tempfile.NamedTemporaryFile("w", suffix=".py", delete=False) as t:

            t.write(src)

        try:

            sys.exit(subprocess.call([sys.executable, t.name]))

        finally:

            os.unlink(t.name)

    elif cmd == "list":

        print(json.dumps(reg, indent=2))

    elif cmd == "mount":

        mount(reg)

    else:

        print(__doc__)



if __name__ == "__main__":

    main(sys.argv)


this no one will understand i promise

  #!/usr/bin/env bash # pyreg.sh: registry-style store in pure bash. # # Here the directory tree IS the registry: keys are directories under...