logoalt Hacker News

nubinetworktoday at 3:22 AM3 repliesview on HN

That's a bug? Happens to me with bash all the time, all I have to do is open 2 terminals at the same time... whichever one I close last is the one that writes its history. /shrug


Replies

praashtoday at 7:29 AM

Running bash inside zsh continuously destroyed my history for the last 3 years until I figured that HISTFILE was exported and inherited by bash.

mmh0000today at 3:57 AM

This is exactly why I stopped using Bash around 2012. I was soooo tired of losing random shell history.

If you haven't looked into ZSH, it has some really nice customizations. Notably, from my config[1]:

  # Remove dups
  setopt HIST_FIND_NO_DUPS
  setopt HIST_IGNORE_DUPS
  # Don't  log commands starting with a space
  setopt HIST_IGNORE_SPACE
  # Replcae bang-command !34 with the actual command in the history
  setopt BANG_HIST
  # Remove extraneous spaces
  setopt HIST_REDUCE_BLANKS
  # Write the history file in the ":start:elapsed;command" format
  setopt EXTENDED_HISTORY
  # Record run-time of the command
  setopt INC_APPEND_HISTORY_TIME
[1] https://doc.xn0.org/.zshrc
valleyertoday at 3:43 AM

That's what zsh's INC_APPEND_HISTORY (mentioned in TFA) avoids. Bash may have an equivalent.