Jayesh Badwaik wrote at 03:18 (EDT) on Saturday:

> Every now and then I want a command from one of the instances of bash
> to be used in another instance. In that case, the history of bash is
> not that useful since it is quiet linear in nature and does not store
> history of all bash instances.

That's not entirely correct.  Bash can be configured to store history
from multiple bash instances and not overwrite.  Here's what I use in my
bashrc to accomplish this:

    HISTSIZE=1048576
    HISTFILESIZE=1048576
    set histappend=true

    LAST_HISTORY_WRITE=$SECONDS
    function prompt_command {
        if [ $(($SECONDS - $LAST_HISTORY_WRITE)) -gt 300 ]; then
            history -a
            LAST_HISTORY_WRITE=$SECONDS
        fi
        ...
    }

This makes sure that all my bash instances save their history and that I
never lose a command.  I have all my bash history going back to
2003-10-15 accessible to me.

The only feature you describe above missing with that configuration is
that existing shells won't find history commands written out
in-between.  I have a tendency to close/open bash shells, so I don't run
into that problem.

Unfortunately, having looked recently at the history code, I think
adding a feature whereby existing running shells "notice" the history
file has changed would be a large rewrite to the history code.  I think
that would be a useful optional feature, though.

> I would like to propose another method of storing the history, just
> like git stores its commits, by using the some kind of hash of the
> command.

I'm not convinced this would accomplish anything of use.  The hashes
would be quite large, and typing them would be annoying, even with tab
completion.

One thing I do is keep my bash_history file in git, by making
.bash_history a symlink to a file in a directory which is stored in
Git.  Perhaps doing that would help you keep better track of your
commands?

-- 
   -- bkuhn

Reply via email to