# shell-history Shell history stored in SQLite, synced via git. ## Install ``` cd $HOME/dev/vlv git clone git.meatbag.se:vlv/shell-history.git shell-history mkdir histdb cd shell-history go build -o shist . sudo install shist /usr/local/bin/ ``` ## Migrate from log files ``` shist import ~/dev/vlv/histdb/ ``` ## zsh `~/.zshrc`: ```zsh autoload -Uz compinit promptinit add-zsh-hook histdb_dir="$HOME/dev/vlv/histdb" _add_history() { if test "$(id -u)" -ne 0; then local cmd=$(fc -ln -1) cmd=${cmd//$'\n'/\\n} shist add \ --timestamp "$(date --utc --iso-8601=seconds)" \ --hostname "$(hostname)" \ --dir "$(pwd)" \ -- "$cmd" fi } add-zsh-hook precmd _add_history hsup() { shist sync "$histdb_dir" } hs() { local copy_cmd= case "$XDG_SESSION_TYPE" in x11) copy_cmd="xsel --clipboard" ;; wayland) copy_cmd="wl-copy --trim-newline" ;; *) echo "Session type not detected."; return ;; esac local entry="$( shist search "$@" | \ fzf --ansi --disabled --query "${*:-}" \ --bind "start:reload:shist search {q}" \ --bind "change:reload:sleep 0.1; shist search {q} || true" \ --delimiter ' ' )" local entry_cmd="$(<<<$entry awk -F' ' '{ print substr($0, index($0, $4)) }')" entry_cmd="${entry_cmd//\\n/$'\n'}" if [[ "$entry" ]]; then eval $copy_cmd <<< "$entry_cmd" >/dev/null echo "Copied to clipboard." >&2 fi } ``` ## Usage ``` shist [--db PATH] add --timestamp T --hostname H --dir D -- COMMAND... shist [--db PATH] search [--host H] [--dir D] [--after T] [--before T] [--limit N] [QUERY...] shist [--db PATH] sync DIR shist [--db PATH] import DIR shist [--db PATH] stats ``` Default `--db`: `~/.local/share/shist/history.db` ## Legacy The old shell scripts (`search.sh`, `sync.sh`) are kept for backward compatibility during migration. They continue to work with the log files in the git repo.