When using ZSH as a shell, the history file can become cluttered with long commands that were accidentally pasted into the terminal. This particularly becomes problematic when you increase the history size since reverse search can begin to take multiple seconds to complete. This script addresses this problem by letting you easily prune your ZSH history.
git clone <gist_url> zsh-history-pruner
python3 zsh-history-pruner/prune_zsh_history.py ~/.zsh_history pruned_zsh_history --char-limit 6000
# Validate pruning result is acceptable
du --human --apparent-size ~/.zsh_history pruned_zsh_history
# Repplace current ZSH history with pruned file
cp ~/.zsh_history ~/.zsh_history.bak
exec mv pruned_zsh_history ~/.zsh_history
This script is released under public domain.