history.zsh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ## History wrapper
  2. function omz_history {
  3. # parse arguments and remove from $@
  4. local clear list stamp
  5. zparseopts -E -D c=clear l=list f=stamp E=stamp i=stamp t:=stamp
  6. if [[ -n "$clear" ]]; then
  7. # if -c provided, clobber the history file
  8. echo -n >| "$HISTFILE"
  9. fc -p "$HISTFILE"
  10. echo >&2 History file deleted.
  11. elif [[ $# -eq 0 ]]; then
  12. # if no arguments provided, show full history starting from 1
  13. builtin fc $stamp -l 1
  14. else
  15. # otherwise, run `fc -l` with a custom format
  16. builtin fc $stamp -l "$@"
  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" -lt 50000 ] && HISTSIZE=50000
  30. [ "$SAVEHIST" -lt 10000 ] && 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 share_history # share command history data