# HSTR Configuration
# Store individual shell history by PID
export HISTFILE="${HOME}/.bash_history_${BASHPID}"

# Point hstr to common history file for cross-shell search
export HSTRFILE="${HOME}/.bash_history_common"

# Ensure history files exist
touch "${HISTFILE}"
touch "${HSTRFILE}"

# Sync history to both common (deduplicated) and local (original settings) files
_hstr_sync_history() {
  local orig_histcontrol="$HISTCONTROL"
  local orig_histfile="$HISTFILE"
  local orig_histfilesize="$HISTFILESIZE"
  
  # Append to common file with deduplication enforced
  export HISTCONTROL=ignoredups:erasedups
  export HISTFILESIZE=10000
  export HISTFILE="${HSTRFILE}"
  history -a
  
  # Restore original settings and append to local file
  export HISTCONTROL="$orig_histcontrol"
  export HISTFILESIZE="$orig_histfilesize"
  export HISTFILE="$orig_histfile"
  history -a
}
