history.zsh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. *) alias history="omz_history -t '$HIST_STAMPS'" ;;
  26. esac
  27. ## History file configuration
  28. [ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
  29. HISTSIZE=50000
  30. SAVEHIST=10000
  31. ## History command configuration
  32. setopt extended_history # record timestamp of command in HISTFILE
  33. setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
  34. setopt hist_ignore_dups # ignore duplicated commands history list
  35. setopt hist_ignore_space # ignore commands that start with space
  36. setopt hist_verify # show command with history expansion to user before running it
  37. setopt inc_append_history # add commands to HISTFILE in order of execution
  38. setopt share_history # share command history data