Unlimited history in Zsh and Bash

It’s a common saying that you don’t miss something until you realize you don’t have it.
This is what happens with shell history.
You execute many commands in your daily tasks but at least from my side, keeping the history and the need to search through all past commands haven’t been a need until I had needed them and I realized that all commands were gone.

So it’s time to set an unlimited history in Zsh and Bash shells.

## Zsh unlimited history
#
export HISTFILESIZE=
export HISTSIZE=
export HISTFILE=~/.zsh_unlimited_history
export HISTTIMEFORMAT="[%F %T] "

setopt INC_APPEND_HISTORY
setopt EXTENDED_HISTORY

This configuration sets an empty value for HISTFILESIZE and HISTSIZE, which allows Zsh to store an unlimited number of commands. It also specifies a custom history file and includes timestamps for each command. Additionally, it enables the INC_APPEND_HISTORY and EXTENDED_HISTORY options for more powerful history management.

# Bash unlimited history
#  
export HISTSIZE=  
export HISTFILESIZE=  
export HISTFILE=~/.bash_unlimited_history  
export HISTTIMEFORMAT="[%F %T] "  
  
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

These configurations make use of environment variables to set HISTSIZE and HISTFILESIZE to unlimited values. The HISTFILE is customized to your preference, and timestamps are included. Moreover, the PROMPT_COMMAND ensures that the history is saved, cleared, and reloaded with each prompt, making your command history continuously available and up to date.

Don’t forget to copy your current history to not lose that part from your unlimited history:

cp .zsh_history .zsh_unlimited_history
cp .bash_history .bash_unlimited_history