logoalt Hacker News

pratyahavatoday at 6:26 AM2 repliesview on HN

this is an example of overcomplicated solutions that could be avoided with the tool we already have for years - file system - why do this "heroic" effort of "cleverly" putting everything in one file from many sessions if we could just write command history of every session into a new separate file in a directory and read all history files from the dir instead of reading one file.


Replies

jasodetoday at 8:02 AM

>why do this "heroic" effort of "cleverly" putting everything in one file from many sessions if we could just write command history of every session into a new separate file in a directory

For "normal" use in the terminal, a unified single history file is easier to deal with. For example, yesterday I was doing some forensics on the existence of mystery files in my backups from years ago and it was nice just loading up a single history file in the editor ... page up and page down repeatedly to eventually reconstruct the sequence of commands that explained the mystery files. The alternate idea of separate history files is less ergonomic for that. I'd have to open each history file (potentially hundreds) one by one in the editor. Trying to treat separate history files as "virtual single file" by using grep on the whole batch wouldn't work because I didn't know ahead of time what string to grep for. It required manually eyeballing the commands to consider which ones were the culprit. (Yes, if history files were separate, I could also concatenate "cat" them all to a temp file and load that into an editor ... but a history file that's already unified means I don't have to bother with that step and delete that temp file after I'm done.)

>HISTFILE="$HOME/zsh/$(date '+%y:%m%d:%H%M')-$$"

However, for "not normal" usage of a shell in a coding editor, I do create separate history files with a timestamp like your suggestion. In dev environments, I tend to create lots of dirty throwaway shell commands and I don't want them polluting the "normal" shell history.

show 1 reply
pratyahavatoday at 6:43 AM

zshrc for saving history:

  mkdir -p $HOME/zsh
  HISTFILE="$HOME/zsh/$(date '+%y:%m%d:%H%M')-$$"
  echo "HISTFILE $HISTFILE"
for easily accessing the history without running grep... will figure it out later :)))