Hacker News new | past | comments | ask | show | jobs | submit login

I fall into the hoard-and-curate camp.

I use bash within tmux heavily, and got irked that a command I run in one shell session is not immediately available as a history item in other concurrent shell sessions. So I wrote a history plugin based on bash-preexec to track everything to two files: a per-directory history file, and a global history file.

I have a bash function which does history selection for me, by popping an fzf selector to look at the directory-specific history file. A keybinding within fzf allows me to switch to looking at the global history file instead.

Boring commands such as “cd”, “pushd”, and a few others don’t get logged. The log entries are in json format and include basic metadata; directory, timestamp, and pid.

Within the fzf history picker, another keybinding allows me to edit whichever file I’m actively using. So if I fumble a few times to construct a command, then when I get it right I just pop into the selector, edit the relevant file, and remove the lines I don’t want to misfire on again.

I’m sure this is basically what atuin does; now that I’m at the spot where directories are the unit of history relevant history, maybe I should give that tool another look.

One really interesting upside of all of this is that I now tend to make “activity-specific” directories in my repos. For example, I have a “.deploy” directory at the git root of most of my projects. There are no files within that directory; but my tool creates ~/.bash.d/history/home/belden/github/company/project/.deploy.json which contains the history of ~/github/company/project/.deploy/

Empty directories are invisible to git, but for me the directory “has” content: the log of how I need to deploy this service or that service.

It’s a weird way to use my shell, and just sprung out of the initial grief: I shouldn’t have to exit a shell session to have its history become available.




> command I run in one shell session is not immediately available as a history item in other concurrent shell sessions

It's hard to understand how any other way is usable. If you have a dozen concurrent shell sessions, some running a long running process for example, and you had to restart one of them, you wouldn't be able to just Ctrl-C and go to the previous command. For me it's way better shell sessions live their own life but the history is accumulated to a single pool.


> command I run in one shell session is not immediately available as a history item in other concurrent shell sessions

this can be solved in vanilla bash by adding these lines to .bashrc (be sure to remove other HIST* configs options from it)

    shopt -s histappend
    export HISTSIZE=100000
    export HISTFILESIZE=100000
    export HISTTIMEFORMAT="%F %T "
    export HISTCONTROL=ignoredups:erasedups
    export PROMPT_COMMAND="history -a;history -c;history -r;$PROMPT_COMMAND"
additionally, you need to restart or close all the bash sessions to be sure no copy of bash with old settings exists


I recommend a few changes to these:

Infinite history instead of a large limit:

  HISTFILESIZE=-1
  HISTSIZE=-1
Also ignore commands starting with a space:

  HISTCONTROL=ignorespace:ignoredups:erasedups
Enable history substitution to verify commands before running them:

  shopt -s histverify
  shopt -s histreedit
Write commands to history files before running the commands instead of after the commands finish:

  trap 'history -a' DEBUG
Or if you already have a DEBUG trap:

  trap "history -a ; $(trap -p DEBUG | cut -d "'" -f 2)" DEBUG



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: