bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash History Behavior Suggestion


From: support
Subject: Re: Bash History Behavior Suggestion
Date: Tue, 20 Aug 2024 14:20:58 -0400
User-agent: Roundcube Webmail

The problem with the tagged format is that it's *not* usable by grep

Awk would have no problem with it.

limited to exactly whatever magic is built into the "history" command

That's where the magic should be. If that were the official interface to `.bash_history`, then bash has freedom to innovate on what is stored, and how it is stored. Then we could add even more information.

Would that be few enough files to satisfy you?

My itch has already been scratched--albeit with a rat's nest of scripts and configurations. With a better history implementation, that could be done away with. Migrating to multiple files for such a low-bandwidth application seems like replacing one rat's nest with another. It would be every bit as brittle as what bash is already doing.

Another option would be to provide a more robust hook for using your own history provider. I put my tweaks in PROMPT_COMMAND, but if we had a HISTAPPEND_COMMAND, we could pass it environment variables relating to all aspects of the last command--start time, end time, cpu, working dir, PID, TTY, etc.

There are several external history providers out there, but they seem to need hundreds of lines of bash to do a proper integration. Making it easier for those tools to capture everything bash knows related to a command would easily halve the size and complexity of those integration scripts.

I've attached an example integration script for https://atuin.sh/. I don't use it myself. I only mention it because it seems to be the most popular one.

You can see that only around 25% of the script is for keybinds and retrieval; the rest is for setting up the capture.

Fields of interest, a running list:

- shell start time
- shell PID
- shell TTY
- command start time (milli/micro)
- command end time (milli/micro)
- command CPU real/user/sys
- command exit code
- command working directory

On 2024-08-20 12:35 pm, Martin D Kealey wrote:
The problem with the tagged format is that it's *not* usable by grep, so
you're limited to exactly whatever magic is built into the "history"
command.

"Yuck" is in the eye of the beholder. I've tried numerous other ways to
segregate sessions, and IMO multiple files was the "least yuck" of many
worse options.

All that said, I would like *some* additional information recorded in the
history file, especially $PWD (when it changes - interpreting "popd"
requires significant mental effort when reading a history file), and
$BASHPID (to track nested shells). With those I would be happy to have
~/.bash_history.d/$TTY, which would greatly reduce the number of files.

Would that be few enough files to satisfy you?

-Martin

On Wed, 21 Aug 2024, 00:38 , <support@eggplantsd.com> wrote:

Bash or no bash, spreading history over dozens of files in
`bash_history.d/` is yuck. We already have a comment with the timestamp
in `.bash_history`. If I were implementing the suggestion, I would add
more information to the comment, then add two new flags to the `history`
command that filter+output the file (i.e. not the internal history
list): `--global` to display everything in `.bash_history`, and
`--local` to restrict output to entries from the current session.
Everything else would remain as-is.

So this:

     #1724136363
     man bash

Becomes this:

     #1724136363 [sess create time] [sess PID] [sess TTY]
     man bash

I think it is important to add the local/global flags because it gives
us some leeway as to how that comment is structured.  If you take the
line of "that's what grep is for", then we're committed to the v1 format
forever after.

The problem with the stackoverflow solutions is that they are
all-or-nothing: either mash the history together across all sessions,
but get strange behavior on history nav & expansion, or don't mash, be
cut-off from information in concurrent sessions, and end up with the
occasional unsaved session. Being able to filter the file directly lets
us look things up without having to slice-and-splice into the internal
history.

On 2024-08-20 6:14 am, Martin D Kealey wrote:
> "Missing/disappearing history" is entirely down to the lack of "writing
> history as you go", and yes that would be reasonable to offer as a new
> opt-in feature.
>
> As for separation of sessions, I strongly suspect that anything between
> *total* separation and *none* will result in so many ugly compromises
> that
> in the end almost nobody will be happy with it. So if there's to be an
> additional option - which I'm not convinced of - I suggest that it
> simply
> be to set HISTFILE by default to either
> $HOME/.bash_history.d/{some-pattern-here} (if the directory exists) or
> ~/.bash_history (matching the current behaviour when that directory
> does
> not exist). I would recommend that the pattern include most or all of
> $$,
> $TTY, $LOGNAME, and $((EPOCHSECONDS-SECONDS)).
>
> Lastly, an awful lot of "default behaviour" is down to whatever
> /etc/skel/.bashrc and /etc/bash/bashrc that are shipped with Bash by
> the
> various distros. Maybe Bash should start shipping some kind of
> "standard
> library" of functions that are *expected* to be included with any
> distro,
> but are not actually built into the binary.
>
> -Martin
>
> PS: complaining about "inelegant" in relation to Bash seems a bit
> pointless.
>
> On Tue, 20 Aug 2024 at 16:48, <support@eggplantsd.com> wrote:
>
>> I wouldn't consider dozens of stackoverflow/askubuntu/etc complaints
>> of
>> missing/disappearing history "cherry-picked".  There were far more
>> than
>> I sent.
>>
>> I understand not wanting to pull the rug out from under people, but
>> the
>> kludges Kealey posted were inelegant.  An opt-in for the suggested
>> behavior would be good enough.
>>
>> JS
>>
>> On 2024-08-20 2:17 am, Lawrence Velázquez wrote:
>> > On Tue, Aug 20, 2024, at 1:42 AM, support@eggplantsd.com wrote:
>> >> The suggestion is that the default behavior needs some work
>> >
>> > The default behavior is unlikely to change.  For every cherry-picked
>> > example of someone unsatisfied with it (bugs aside), there is likely
>> > someone else who prefers it as is (or at least would not appreciate
>> > it changing out from under them).  New shopt settings may be doable.
>>
>>

Attachment: atuin.sh
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]