history.zsh 1.5 KB

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