history.zsh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ## History wrapper
  2. function omz_history {
  3. # parse arguments and remove from $@
  4. local clear list stamp REPLY
  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. # confirm action before deleting history
  9. print -nu2 "This action will irreversibly delete your command history. Are you sure? [y/N] "
  10. builtin read -k1
  11. [[ "$REPLY" = $'\n' ]] || print -u2
  12. [[ "$REPLY" != ([yY]) ]] && return 0
  13. print -nu2 >| "$HISTFILE"
  14. fc -p "$HISTFILE"
  15. print -u2 History file deleted.
  16. elif [[ $# -eq 0 ]]; then
  17. # if no arguments provided, show full history starting from 1
  18. builtin fc $stamp -l 1
  19. else
  20. # otherwise, run `fc -l` with a custom format
  21. builtin fc $stamp -l "$@"
  22. fi
  23. }
  24. # Timestamp format
  25. case ${HIST_STAMPS-} in
  26. "mm/dd/yyyy") alias history='omz_history -f' ;;
  27. "dd.mm.yyyy") alias history='omz_history -E' ;;
  28. "yyyy-mm-dd") alias history='omz_history -i' ;;
  29. "") alias history='omz_history' ;;
  30. *) alias history="omz_history -t '$HIST_STAMPS'" ;;
  31. esac
  32. ## History file configuration
  33. [ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
  34. [ "$HISTSIZE" -lt 50000 ] && HISTSIZE=50000
  35. [ "$SAVEHIST" -lt 10000 ] && SAVEHIST=10000
  36. ## History command configuration
  37. setopt extended_history # record timestamp of command in HISTFILE
  38. setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
  39. setopt hist_ignore_dups # ignore duplicated commands history list
  40. setopt hist_ignore_space # ignore commands that start with space
  41. setopt hist_verify # show command with history expansion to user before running it
  42. setopt share_history # share command history data