Files
self-healing-autopoietic-shell/contrib/fx/sources.d/20-history.sh
T

12 lines
512 B
Bash
Executable File

#!/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.
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 | grep -F -- "$first_word " | grep -vF -- "$cmd" | awk '!seen[$0]++' | tail -5