history.zsh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ## History wrapper
  2. function omz_history {
  3. # Delete the history file if `-c' argument provided.
  4. # This won't affect the `history' command output until the next login.
  5. zparseopts -E c=clear l=list
  6. if [[ -n "$clear" ]]; then
  7. # if -c provided, clobber the history file
  8. echo -n >| "$HISTFILE"
  9. echo >&2 History file deleted. Reload the session to see its effects.
  10. elif [[ -n "$list" ]]; then
  11. # if -l provided, run as if calling `fc' directly
  12. builtin fc "$@"
  13. else
  14. # otherwise, call `fc -l 1` to show all available
  15. # history (and pass additional parameters)
  16. builtin fc "$@" -l 1
  17. fi
  18. }
  19. # Timestamp format
  20. case $HIST_STAMPS in
  21. "mm/dd/yyyy") alias history='omz_history -f' ;;
  22. "dd.mm.yyyy") alias history='omz_history -E' ;;
  23. "yyyy-mm-dd") alias history='omz_history -i' ;;
  24. *) alias history='omz_history' ;;
  25. esac
  26. ## History file configuration
  27. [ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
  28. HISTSIZE=50000
  29. SAVEHIST=10000
  30. ## History command configuration
  31. setopt extended_history # record timestamp of command in HISTFILE
  32. setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
  33. setopt hist_ignore_dups # ignore duplicated commands history list
  34. setopt hist_ignore_space # ignore commands that start with space
  35. setopt hist_verify # show command with history expansion to user before running it
  36. setopt inc_append_history # add commands to HISTFILE in order of execution
  37. setopt share_history # share command history data