Merge pull request #3422 from mcornella/fix-history-alias
Enhance history alias
Diff
1diff --git a/lib/history.zsh b/lib/history.zsh
2index 5de71c2d3e0fdd0296cc8d46da9fbd1724fd7a00..7d4e59d0058ceb33c5305a6616291dc4a2b75f8c 100644
3--- a/lib/history.zsh
4+++ b/lib/history.zsh
5@@ -1,24 +1,41 @@
6-## Command history configuration
7-if [ -z "$HISTFILE" ]; then
8- HISTFILE=$HOME/.zsh_history
9-fi
10+## History wrapper
11+function omz_history {
12+ # Delete the history file if `-c' argument provided.
13+ # This won't affect the `history' command output until the next login.
14+ zparseopts -E c=clear l=list
1516-HISTSIZE=10000
17-SAVEHIST=10000
18+ if [[ -n "$clear" ]]; then
19+ # if -c provided, clobber the history file
20+ echo -n >| "$HISTFILE"
21+ echo >&2 History file deleted. Reload the session to see its effects.
22+ elif [[ -n "$list" ]]; then
23+ # if -l provided, run as if calling `fc' directly
24+ builtin fc "$@"
25+ else
26+ # otherwise, call `fc -l 1` to show all available
27+ # history (and pass additional parameters)
28+ builtin fc "$@" -l 1
29+ fi
30+}
3132-# Show history
33+# Timestamp format
34 case $HIST_STAMPS in
35- "mm/dd/yyyy") alias history='fc -fl 1' ;;
36- "dd.mm.yyyy") alias history='fc -El 1' ;;
37- "yyyy-mm-dd") alias history='fc -il 1' ;;
38- *) alias history='fc -l 1' ;;
39+ "mm/dd/yyyy") alias history='omz_history -f' ;;
40+ "dd.mm.yyyy") alias history='omz_history -E' ;;
41+ "yyyy-mm-dd") alias history='omz_history -i' ;;
42+ *) alias history='omz_history' ;;
43 esac
4445-setopt append_history
46-setopt extended_history
47-setopt hist_expire_dups_first
48-setopt hist_ignore_dups # ignore duplication command history list
49-setopt hist_ignore_space
50-setopt hist_verify
51-setopt inc_append_history
52-setopt share_history # share command history data
53+## History file configuration
54+[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
55+HISTSIZE=50000
56+SAVEHIST=10000
57+
58+## History command configuration
59+setopt extended_history # record timestamp of command in HISTFILE
60+setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
61+setopt hist_ignore_dups # ignore duplicated commands history list
62+setopt hist_ignore_space # ignore commands that start with space
63+setopt hist_verify # show command with history expansion to user before running it
64+setopt inc_append_history # add commands to HISTFILE in order of execution
65+setopt share_history # share command history data