Files
adaptiveos/root/shell-project/contrib/fx/sources.d/20-history.sh
T
Daveswo 77856f0a09 Initial commit: apkovl deployment source, synced from shell-project main
This directory is what gets packaged into localhost.apkovl.tar.gz and
baked into adaptiveos-vN.iso. It had drifted out of sync with the real
project (root/shell-project/ had gone missing entirely at some point
after being written earlier this session -- cause unconfirmed, Desktop
is a plausible sync-related suspect but not verified) and separately
carried a stale, pre-fix copy of fx.sh.

Current contents:
  etc/profile.d/adaptive-loop.sh   -- disk-persists p AND p.trace
                                       (fx()'s fix-provenance record)
                                       across reboot, two separate 1MB
                                       blocks on the attached state disk
  etc/profile.d/adaptive-setup.sh  -- unchanged, network/git/fzf bring-up
  root/shell-project/              -- synced from space.seodr.ovh/
                                       Daveswo/self-healing-autopoietic-
                                       shell @ 3c4947e (main), plus three
                                       deployment-only files not in that
                                       repo: contrib/fx/builtin-fixes.txt,
                                       contrib/fx/sources.d/15-builtin-
                                       fixes.sh, contrib/heal/heal.sh

Verified byte-identical to what's actually embedded in the currently
shipping adaptiveos-v6.iso before this commit (full recursive diff),
and every .sh file passes `sh -n`.

.gitattributes (text=auto eol=lf) added to prevent the CRLF corruption
that hit the canonical repo earlier this session from recurring here.
2026-08-22 02:55:40 -04:00

26 lines
1015 B
Bash

#!/bin/sh
# History source: suggests the closest-looking command you've actually
# typed and moved on from before (thefuck's history.py idea). Reads
# HISTFILE directly since a separate process doesn't inherit the parent
# shell's in-memory history.
#
# Single awk pass over the tail of the file: on weak/emulated hardware
# every avoided fork+exec matters (measured: an unoptimized PATH walk in
# 40-pathfuzzy.sh took >30s on this box before being fixed; pipeline
# depth has the same tax, just smaller per-hop) -- a five-process
# tail|grep|grep|awk|tail chain does the same job as one awk script
# reading the file once.
cmd="$1"
first_word=$(printf '%s' "$cmd" | awk '{print $1}')
[ -n "$first_word" ] || exit 0
hf="${HISTFILE:-$HOME/.bash_history}"
[ -r "$hf" ] || exit 0
tail -n 300 "$hf" 2>/dev/null | awk -v first="$first_word" -v full="$cmd" '
index($0, first " ") == 1 && $0 != full && !seen[$0]++ { buf[++n] = $0 }
END {
start = (n > 5) ? n - 4 : 1
for (i = start; i <= n; i++) print buf[i]
}
'