sorry, I meant HISTTIMEFORMAT rather than HISTTIMEFMT On Tue, 20 Aug 2024 at 14:58, Martin D Kealey <mar...@kurahaupo.gen.nz> wrote:
> The following suggestions, or close approximations, can all be implemented > using the existing facilities. > > On Tue, 20 Aug 2024 at 05:52, <supp...@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. >