Unlimited bash/zsh history

In bash or zsh the history is my documentation. I have a unlimited history, or at least a super huge history. Once I typed a command into my terminal, on that very machine, it will be there forever or at least for a very long time.

And I have nice autocompletion. If I ever had typed some commands, say cmake -S . -B build and cmake --build build.
If I type cmake + ArrowUp key, it will autocomplete to cmake --build build.
Another ArrowUo will autocomplete to cmake -S . -B build.
You get the point. It takes the written letters and searches through the history all command that started with the letters typed.

I have explained that bash/zsh setup often enough to finally write it down.


This is what I have in my .zshrc file

#use a history file in here
# make it huge, really huge.

# there is for sure still some redundancy, but ...
# setopt BANG_HIST                 # Treat the '!' character specially during expansion.
# setopt EXTENDED_HISTORY          # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY        # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY             # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST    # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS          # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS      # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS         # Do not display a line previously found.
setopt HIST_IGNORE_SPACE         # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS         # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS        # Remove superfluous blanks before recording entry.
#setopt HIST_VERIFY               # Don't execute immediately upon history expansion.
#setopt HIST_BEEP                 # Beep when accessing nonexistent history.

alias history="history 0"

and this in my .zprofile

# this puts the curser on the end?
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[[A" history-beginning-search-backward-end
bindkey "^[[B" history-beginning-search-forward-end


My bash setup is not as detailed but works also

In my .bash_profile I have

# unlimited history
export HISTSIZE=
# no duplicates
export HISTCONTROL=ignoreboth:erasedups
# use a specific file
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
PROMPT_COMMAND="history -a; history -c; history -r"

For navigation the history with autocompletion there is this in my .bashrc

bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

Possible improvements?

I have none. The command I typed 3 months ago …​ what was it? Its in the history. If I remember the first letters I have even a nice search for it. I am happy.

But if you know about any improvements that could be added, please let me know. Just put them in the comment section below. Thanks in advance!