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 01:42:48 -0400
User-agent: Roundcube Webmail

I know it can. The suggestion is that the default behavior needs some work:

https://askubuntu.com/questions/67283/is-it-possible-to-make-writing-to-bash-history-immediate
https://askubuntu.com/questions/80371/bash-history-handling-with-multiple-terminals
https://askubuntu.com/questions/885531/half-of-bash-history-is-missing
https://askubuntu.com/questions/261407/how-to-save-terminal-history-manually

On 2024-08-20 12:58 am, Martin D Kealey wrote:
The following suggestions, or close approximations, can all be implemented
using the existing facilities.

On Tue, 20 Aug 2024 at 05:52, <support@eggplantsd.com> wrote:

I would suggest:

1. Append to history file immediately on each command.


Easily done by putting `history -a` into `PROMPT_COMMAND`

2. Restrict up-arrow completion to the history of present session.


That's easy. Simply don't use `history -r` in your .bashrc or
/etc/bash/bashrc.

(Unfortunately modifying the latter will require admin access to your host, so choose a distro that does NOT include `history -r` among its system-wide
shell start-up files.)

3. Add column(s) to the history file to identify the session the command
came from (pty, pid, etc).


I simply write the history for each session into a separate file; I have

 HISTFILE=$HOME/.bash_history.d/$EPOCHSECONDS.$TTY.$$

That way I can simply use a pager such as `less` to read the file I'm
interested in. If I want to see the timestamps, I can use:

  ( HISTTIMEFMT="%F,%T " HISTFILE={other-history-file} ; history -c ;
history -r ; history ) | less

4. Add options to the 'history' command to toggle between session-local
and global reporting.


I simply use separate commands to view the current session's history vs all
sessions.
I generally prefer not to interleave multiple sessions, but on the rare
occasion when I do want this, I can simply use:

( cd $HOME/.bash_history.d ; HISTTIMEFORMAT="%F,%T " ; for HISTFILE in * ;
do ( history -c ; history -r ; history ) ; done ) | sort | less

If I did this often enough to actually care, I'd wrap it in a function.



reply via email to

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