Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Bash's broken history is what finally got me to switch to Zsh. The history behavior you want is: 1. each line of history is appended incrementally, but 2. each shell session only has access to its own history unless you specifically reload the history into your session.

Every combination of history commands in bash didn't do the right thing[1], but Zsh's works as desired.

[1] eg. putting 'history -a' in PROMPT_COMMAND as the article recommends appends your session's entire history each time, IIRC.



See, what I want from my history is every command I have ever run, so that ctrl r can find anything I have done.


Yes what I wrote doesn't exclude that. The only distinction is that you generally don't want all your sessions' histories interleaved. I.e. when you up-arrow, you only want your current session's history, without random things from other active sessions in there too. If you do want "everything you've ever done" including things from other sessions that started after your current session, it's easy to reload your history into your session. I have a 'rlh' (reload history) alias for that.


You always only have your current session history in each bash (unless you reload the history manually) so there is no interleaving.


Yeah I know, I was just making a distinction from cortesoft's "I want everything I've ever done" in my history. I was saying "so do I, except I want active sessions separate" (which as you point out, they are by default).


> [1] eg. putting history -a in PROMPT_COMMAND as the article recommends appends your session's entire history each time, IIRC.

No, only the last command. Very handy because that way you can start a new terminal and have your current history available immediately. I also have an alias r='history -n'. With this you can load the history of another terminal session directly into the current session.


Just tested it and 'history -a' behaves how you say. Maybe it was an older version of bash that had this behavior.

Edit: now I'm obsessing about reproducing this behavior from years ago! If anyone knows what I'm talking about I'd be grateful for some validation :)


`setopt inc_append_history_time` is super useful for Zsh users. This gives you some sharing of histories between shells.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: