pxh is a fast, cross-shell history mining tool with interactive fuzzy search,
secret scanning, and bidirectional sync across machines. It indexes bash and
zsh history in SQLite with rich metadata for powerful recall.
preexec(){localcmd="$1"[-z"$cmd"]&&return 1[["$cmd"=~^[[:space:]]]]&&return 1localstarted=$(date +%s)pxh\
--db"$PXH_DB_PATH"\
insert \
--working-directory"$PWD"\
--hostname"$PXH_HOSTNAME"\
--shellname bash \
--username"$USER"\
--session-id"$PXH_SESSION_ID"\
--start-unix-timestamp"$started"\
"$cmd"}precmd(){localretval=$?localended=$(date +%s)pxh\
--db"$PXH_DB_PATH"\
seal \
--session-id"$PXH_SESSION_ID"\
--end-unix-timestamp"$ended"\
--exit-status"$retval"}_pxh_random(){od -An -N6 -tu8< /dev/urandom|tr -d'\n '}_pxh_recall(){localselectedselected=$(pxh --db"$PXH_DB_PATH" recall --shell-mode --query"$READLINE_LINE"2>/dev/null)if[["$selected"== run:*]];then# Execute immediatelyREADLINE_LINE="${selected#run:}"READLINE_POINT=${#READLINE_LINE}# Simulate pressing Enter by accepting the line# Note: bind -x functions can't directly execute, so we rely on# the user pressing Enter or we could use READLINE_LINE and accept-lineelif[["$selected"== edit:*]];then# Place in buffer for editingREADLINE_LINE="${selected#edit:}"READLINE_POINT=${#READLINE_LINE}fi}_pxh_init(){PXH_SESSION_ID=$(_pxh_random)PXH_HOSTNAME=$(hostname -s)exportPXH_DB_PATH=${PXH_DB_PATH:-$HOME/.pxh/pxh.db}[!-d"$(dirname"$PXH_DB_PATH")"]&&mkdir -p -m 0700 "$(dirname"$PXH_DB_PATH")"# Bind Ctrl-R to pxh recall # PXH_CTRL_R_BINDINGbind-x'"\C-r": _pxh_recall'# PXH_CTRL_R_BINDING}_pxh_init