-
-
Save MartinHeinz/d233819a1041eae1700fa28ac8937229 to your computer and use it in GitHub Desktop.
| export ZSH="$HOME/.oh-my-zsh" | |
| ZSH_THEME="ys" | |
| HISTFILE="$HOME/.zsh_history" | |
| HISTSIZE=10000000 | |
| SAVEHIST=10000000 | |
| HISTORY_IGNORE="(ls|cd|pwd|exit|cd)*" | |
| HIST_STAMPS="yyyy-mm-dd" | |
| 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/oh-my-zsh.sh | |
| export FZF_DEFAULT_COMMAND='ag --hidden -g ""' | |
| source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh |
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')
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.
Cheers
Just noticed there are two
cdcommands inHISTORY_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')
The syntax is indeed correct, zshparam(1) says:
Note that HISTORY_IGNORE defines a single pattern: to specify alternatives use the β(first|second|...)' syntax.
Great article! π https://martinheinz.dev/blog/110
Some notes you may consider including in the blog post:
INC_APPEND_HISTORYis not needed whenSHARE_HISTORYis set since sharing history requires writing to the history file immediatelyTypically you would only enable one of:
HIST_IGNORE_DUPS/HIST_SAVE_NO_DUPS/HIST_IGNORE_ALL_DUPSsince their behaviors are unique:
HIST_IGNORE_DUPSonly ignores consecutive duplicates, so if you enterls, thencd, thenlsagain, the secondlswill be saved because it is not consecutiveHIST_SAVE_NO_DUPSprevents 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 enteredHIST_IGNORE_ALL_DUPSensures 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_STOREis just another name forHIST_IGNORE_SPACEso only one needs to be set (I preferHIST_IGNORE_SPACEsince it explicitly mentions the space which helps to remember what this option does)
This is not true. You can see in the source code that HIST_NO_STORE and HIST_IGNORE_SPACE do separate things. Search for histnostore and histignorespace to see the logic. I haven't checked the full logic for the HIST_IGNORE_xxx flags but if you search the source you can see that they do indeed do different things and may not trivially exclude each other.
Your statement about INC_APPEND_HISTORY and SHARE_HISTORY is also incorrect. See the block comment on line 1172 in the linked source that explains the logic when they are enabled together. The actual logic is that SHARE_HISTORY will only write immediately to the history file if it is not already locked:
/*
* For normal INCAPPENDHISTORY case and reasoning, see hbegin().
*/
if (isset(SHAREHISTORY) ? histfileIsLocked() :
(isset(INCAPPENDHISTORY) || (isset(INCAPPENDHISTORYTIME) &&
histsave_stack_pos != 0)))
savehistfile(hf, 0, HFILE_USE_OPTIONS | HFILE_FAST);
unlockhistfile(hf); /* It's OK to call this even if we aren't locked */@nastynaz Thank you for correcting me π And I will definitely read through the information you shared when I have time to do so.
Thanks again for the corrections. Very much appreciated.
I tried to find where on earth I mistakenly learned that HIST_NO_STORE was another name for HIST_IGNORE_SPACE, but could not find the source that I might have gotten that incorrect info from.
Regarding HIST_IGNORE_DUPS, HIST_SAVE_NO_DUPS and HIST_IGNORE_ALL_DUPS, my intention was not that they "exclude each other", but rather that in practical terms, only one of them is typically enabled.
And regarding INC_APPEND_HISTORY and SHARE_HISTORY, my comment was based on this man page content which instructs to turn off INC_APPEND_HISTORY when when using SHARE_HISTORY:
SHARE_HISTORY <K>
This option both imports new commands from the history file, and also causes your typed commands to be
appended to the history file (the latter is like specifying INC_APPEND_HISTORY, which should be turned
off if this option is in effect).
Great article! π https://martinheinz.dev/blog/110
Some notes you may consider including in the blog post:
INC_APPEND_HISTORYis not needed whenSHARE_HISTORYis set since sharing history requires writing to the history file immediatelyTypically you would only enable one of:
HIST_IGNORE_DUPS/HIST_SAVE_NO_DUPS/HIST_IGNORE_ALL_DUPSsince their behaviors are unique:HIST_IGNORE_DUPSonly ignores consecutive duplicates, so if you enterls, thencd, thenlsagain, the secondlswill be saved because it is not consecutiveHIST_SAVE_NO_DUPSprevents 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 enteredHIST_IGNORE_ALL_DUPSensures that only the most recent instance of any command is preserved by removing earlier duplicates from the history whenever a command is re-enteredHIST_NO_STOREis just another name forHIST_IGNORE_SPACEso only one needs to be set (I preferHIST_IGNORE_SPACEsince it explicitly mentions the space which helps to remember what this option does)