Optimizing Shell History
-I've spent a lot of time fiddling with my local development environment over - the years. As a result, I've also evolved how I interact with my shell history.
-I would say that I use my history as a convenience and efficiency booster, - though I do not use it to drive workflow to the extent I see from others.
-I take advantage of three things:
--
-
- History configuration settings. -
- Shell comments. -
- Fuzzy search (FZF, in this case). -
History Configuration
-I currently use zsh, so the example below is
- for zsh.
export HISTFILE="$HOME/.zsh_history"
-export HISTSIZE=25000
-export SAVEHIST=$HISTSIZE
-export HISTORY_IGNORE="(ls|cd|pwd|exit)*"
-
-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.
-setopt INTERACTIVE_COMMENTS # Allow comments in interactive shell.
-
-# Example of what I have - you can use your own configuration. Note that this
-# example is intended for use on wayland with wl-copy.
-export FZF_CTRL_R_OPTS="
- --preview 'echo {}' --preview-window up:3:hidden:wrap
- --bind 'ctrl-/:toggle-preview'
- --bind 'ctrl-y:execute-silent(echo -n {2..} | wl-copy)+abort'
- --color header:italic
- --header 'Press CTRL-Y to copy command into clipboard'"
-