Skip to content

Instantly share code, notes, and snippets.

Created April 1, 2024 10:10
Show Gist options
  • Save MartinHeinz/d233819a1041eae1700fa28ac8937229 to your computer and use it in GitHub Desktop.
Save MartinHeinz/d233819a1041eae1700fa28ac8937229 to your computer and use it in GitHub Desktop.
export ZSH="$HOME/.oh-my-zsh"
bindkey "^E" history-incremental-search-backward
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_IGNORE_DUPS # Do not record an event that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete an old recorded event if a new event is a duplicate.
setopt HIST_IGNORE_SPACE # Do not record an event starting with a space.
setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file.
setopt HIST_VERIFY # Do not execute immediately upon history expansion.
setopt APPEND_HISTORY # append to history file (Default)
setopt HIST_NO_STORE # Don't store history commands
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks from each command line being added to the history list.
plugins=(git fzf)
source $ZSH/
export FZF_DEFAULT_COMMAND='ag --hidden -g ""'
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
Copy link

Great article! 👍

Some notes you may consider including in the blog post:

  • INC_APPEND_HISTORY is not needed when SHARE_HISTORY is set since sharing history requires writing to the history file immediately

  • Typically you would only enable one of: HIST_IGNORE_DUPS/HIST_SAVE_NO_DUPS/HIST_IGNORE_ALL_DUPS since their behaviors are unique:

    • HIST_IGNORE_DUPS only ignores consecutive duplicates, so if you enter ls, then cd, then ls again, the second ls will be saved because it is not consecutive
    • HIST_SAVE_NO_DUPS prevents a command from being saved if it is a duplicate of any existing entry in the history, but it doesn't remove earlier instances of a command when a new one is entered
    • HIST_IGNORE_ALL_DUPS ensures that only the most recent instance of any command is preserved by removing earlier duplicates from the history whenever a command is re-entered
  • HIST_NO_STORE is just another name for HIST_IGNORE_SPACE so only one needs to be set (I prefer HIST_IGNORE_SPACE since it explicitly mentions the space which helps to remember what this option does)

Copy link

Just noticed there are two cd commands in HISTORY_IGNORE="(ls|cd|pwd|exit|cd)*"

Nonetheless, I kindly suggest testing to ensure that syntax is working as expected. I thought the syntax needed to be something like:

HISTORY_IGNORE=('ls' 'ls *' 'cd' 'cd *' 'pwd' 'exit')

Copy link

Thanks a lot for the article!

In case anyone runs into the same issue, I had to install fzf in order to have the ZSH fzf (just fzf for me, instead of git fzf) plugin work. Otherwise, I was prompted to specify FZF's installation dir.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment