summaryrefslogtreecommitdiff
path: root/src/remembering.in
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2026-06-12 09:19:28 -0300
committerEuAndreh <eu@euandre.org>2026-06-12 09:19:28 -0300
commit46fd0362bce11d709e5efe6d540358533985d363 (patch)
treef77d2ed33c4f3fb6e85353e436efca4e19028f73 /src/remembering.in
parentrm .tdrc COPYING (diff)
downloadremembering-46fd0362bce11d709e5efe6d540358533985d363.tar.gz
remembering-46fd0362bce11d709e5efe6d540358533985d363.tar.xz
Rewrite remembering in Go
The shell pipeline (sed | sort | tee | awk | sort | cut | "$@" plus the cut | uniq | awk profile rewrite) becomes a single static binary with the same observable behaviour, pinned by the original ranking.sh, signals.sh and cli-opts.sh suites, now aimed at remembering.bin: - the profile keeps the exact on-disk format, COUNT profile TEXT, byte-sorted with new picks appended at 1 and offered-but-never- picked entries persisted at 0; - the menu stays count-descending with byte-order ties, stdin alone defines what is offered, and duplicate profile lines sum for ranking but collapse to the highest count on rewrite, as sort | uniq -f1 did; - the wrapped command's exit status is forwarded as-is (128+sig for signal deaths), its stderr passes through, and an empty pick learns nothing; - the profile rewrite stays atomic via .tmp plus rename. Per the house CLI conventions, -h/-V/--help/--version are gone (the manpage is the documentation; bad options print the usage on stderr and exit 2), and getopts-style attached option arguments (-pNAME) are not accepted any more --- no script in the wild used them. The project layout follows rot: raw go tool compile/link Makefile, mkdeps.sh-generated deps.mk, white-box unit suite, fuzz target over the profile parse/serialize roundtrip, functional pick roundtrip, a 1M-line ranking benchmark, and a single English asciidoc manpage absorbing the old .5 page; the po4a/aux release machinery goes away. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'src/remembering.in')
-rwxr-xr-xsrc/remembering.in165
1 files changed, 0 insertions, 165 deletions
diff --git a/src/remembering.in b/src/remembering.in
deleted file mode 100755
index 89e9453..0000000
--- a/src/remembering.in
+++ /dev/null
@@ -1,165 +0,0 @@
-#!/bin/sh
-set -eu
-
-
-usage() {
- cat <<-'EOF'
- Usage:
- @NAME@ [-p PROFILE] -- COMMAND...
- @NAME@ -h|-V
- EOF
-}
-
-help() {
- cat <<-'EOF'
-
- Options:
- -p PROFILE profile to be used for gathering and storing
- data (default: create one based on $PWD)
- -h, --help show this message
- -V, --version print the version number
-
- COMMAND command to be ran, reading from
- STDIN, writing to STDOUT
-
-
- Explanation FIXME.
-
- See "man @NAME@" for more information.
-
-
- Examples:
-
- FIXME:
-
- $ FIXME
- EOF
-}
-
-version() {
- printf '%s %s %s\n' '@NAME@' '@VERSION@' '@DATE@'
-}
-
-
-uuid() {
- od -xN20 /dev/urandom |
- head -n1 |
- awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
-}
-
-tmpname() {
- echo "${TMPDIR:-/tmp}/@NAME@.tmpfile.$(uuid)"
-}
-
-mkstemp() {
- name="$(tmpname)"
- touch "$name"
- echo "$name"
-}
-
-
-for flag in "$@"; do
- case "$flag" in
- --)
- break
- ;;
- --help)
- usage
- help
- exit
- ;;
- --version)
- version
- exit
- ;;
- *)
- ;;
- esac
-done
-
-PROFILE_NAME="$(pwd | tr '/' '!')"
-while getopts 'p:hV' flag; do
- case "$flag" in
- p)
- PROFILE_NAME="$OPTARG"
- ;;
- h)
- usage
- help
- exit
- ;;
- V)
- version
- exit
- ;;
- *)
- usage >&2
- exit 2
- ;;
- esac
-done
-shift $((OPTIND - 1))
-
-
-if [ $# = 0 ]; then
- printf 'Missing "-- COMMAND"\n' >&2
- usage >&2
- exit 2
-fi
-
-NAME='@NAME@'
-PROFILE="${XDG_DATA_HOME:-$HOME/.local/share}"/$NAME/"$PROFILE_NAME"
-
-if [ ! -e "$PROFILE" ]; then
- mkdir -p "$(dirname "$PROFILE")"
- touch "$PROFILE"
-fi
-
-NEXT_PROFILE="$PROFILE".tmp
-MERGED="$(mkstemp)"
-FILTERED="$(mkstemp)"
-trap 'rm -f "$NEXT_PROFILE" "$MERGED" "$FILTERED"' EXIT
-CHOICE="$(
- cat - |
- sed 's/^/0 stdin /' |
- sort -k3 -k1nr - "$PROFILE" |
- tee "$MERGED" |
- awk '
- { rest = substr($0, 3 + length($1) + length($2)) }
- $2 == "profile" { seen[rest] += $1 }
- $2 == "stdin" { printf "%s %s\n", seen[rest]+0, rest }
- ' |
- sort -k1nr |
- cut -d' ' -f2- |
- "$@"
-)"
-
-if [ -z "$CHOICE" ]; then
- exit
-fi
-
-< "$MERGED" \
- cut -d' ' -f1,3- |
- uniq -f1 |
- awk -vCHOICE="$CHOICE" '
- BEGIN { inc = 1 }
-
- { rest = substr($0, 2 + length($1)) }
-
- rest == CHOICE {
- printf "%s profile %s\n", $1 + inc, rest
- found = 1
- next
- }
-
- { printf "%s profile %s\n", $1, rest }
-
- END {
- if (!found) {
- printf "%s profile %s\n", 0 + inc, CHOICE
- }
- }
- ' > "$NEXT_PROFILE"
-
-mv "$NEXT_PROFILE" "$PROFILE"
-printf '%s\n' "$CHOICE"