history.zsh 1.5 KB

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