From d87d4331cfab6cffbcc2366a855855b9a5c5e848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 15 Jun 2014 21:08:04 +0200 Subject: [PATCH 1/8] Change history alias into a function This commit changes the history alias into a function which puts the passed arguments before `-l 1`. It also provides a temporary workaround to the lack of a `history -c` command in zsh. For more information see issues 739 and 789. --- lib/history.zsh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/history.zsh b/lib/history.zsh index 5de71c2d..8a861fdb 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -6,12 +6,24 @@ fi HISTSIZE=10000 SAVEHIST=10000 -# Show history +## History wrapper +function omz_history { + # Delete the history file if `-c' argument provided. + # This won't affect the `history' command output until the next login. + if [[ "${@[(i)-c]}" -le $# ]]; then + echo -n >| "$HISTFILE" + echo >&2 History file deleted. Reload the session to see its effects. + else + fc $@ -l 1 + fi +} + +# Timestamp format case $HIST_STAMPS in - "mm/dd/yyyy") alias history='fc -fl 1' ;; - "dd.mm.yyyy") alias history='fc -El 1' ;; - "yyyy-mm-dd") alias history='fc -il 1' ;; - *) alias history='fc -l 1' ;; + "mm/dd/yyyy") alias history='omz_history -f' ;; + "dd.mm.yyyy") alias history='omz_history -E' ;; + "yyyy-mm-dd") alias history='omz_history -i' ;; + *) alias history='omz_history' ;; esac setopt append_history From 94baa9eadd05038a343bfd99f01493123f5a1526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 13 Dec 2014 23:20:03 +0100 Subject: [PATCH 2/8] Simplify `if' into oneliner, allow spaces in HISTFILE --- lib/history.zsh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/history.zsh b/lib/history.zsh index 8a861fdb..058a1a31 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -1,8 +1,5 @@ ## Command history configuration -if [ -z "$HISTFILE" ]; then - HISTFILE=$HOME/.zsh_history -fi - +[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" HISTSIZE=10000 SAVEHIST=10000 From 643bb25a0d2bd5c2ef316a88021e1ac4eb156bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sat, 13 Dec 2014 23:31:56 +0100 Subject: [PATCH 3/8] Organize history.zsh file and improve comments --- lib/history.zsh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/history.zsh b/lib/history.zsh index 058a1a31..da1e02dd 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -1,8 +1,3 @@ -## Command history configuration -[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" -HISTSIZE=10000 -SAVEHIST=10000 - ## History wrapper function omz_history { # Delete the history file if `-c' argument provided. @@ -23,11 +18,17 @@ case $HIST_STAMPS in *) alias history='omz_history' ;; esac -setopt append_history -setopt extended_history -setopt hist_expire_dups_first -setopt hist_ignore_dups # ignore duplication command history list -setopt hist_ignore_space -setopt hist_verify -setopt inc_append_history -setopt share_history # share command history data +## History file configuration +[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" +HISTSIZE=10000 +SAVEHIST=10000 + +## History command configuration +setopt append_history # append history to HISTFILE on session exit +setopt extended_history # record timestamp of command in HISTFILE +setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE +setopt hist_ignore_dups # ignore duplicated commands history list +setopt hist_ignore_space # ignore commands that start with space +setopt hist_verify # show command with history expansion to user before running it +setopt inc_append_history # add commands to HISTFILE in order of execution +setopt share_history # share command history data From 03758416fe99f0f1cb9f19ad1a7846de1b02f21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 18 Dec 2014 12:08:56 +0100 Subject: [PATCH 4/8] Ensure builtin fc is used (see #3001) --- lib/history.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/history.zsh b/lib/history.zsh index da1e02dd..21e9c756 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -6,7 +6,7 @@ function omz_history { echo -n >| "$HISTFILE" echo >&2 History file deleted. Reload the session to see its effects. else - fc $@ -l 1 + builtin fc "$@" -l 1 fi } From f8180c3a64754057d696a4fb1cf3639c394377b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 18 Dec 2014 20:36:56 +0100 Subject: [PATCH 5/8] Allow overriding -l flag in history --- lib/history.zsh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/history.zsh b/lib/history.zsh index 21e9c756..e6c94fcc 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -5,6 +5,8 @@ function omz_history { if [[ "${@[(i)-c]}" -le $# ]]; then echo -n >| "$HISTFILE" echo >&2 History file deleted. Reload the session to see its effects. + elif [[ "${@[(i)-l]}" -le $# ]]; then + builtin fc "$@" else builtin fc "$@" -l 1 fi From 20d63be655bfed2104858dc87052a310f9c45224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 18 Dec 2014 21:56:49 +0100 Subject: [PATCH 6/8] Use zparseopts to get passed arguments --- lib/history.zsh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/history.zsh b/lib/history.zsh index e6c94fcc..23e96c9d 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -2,12 +2,18 @@ function omz_history { # Delete the history file if `-c' argument provided. # This won't affect the `history' command output until the next login. - if [[ "${@[(i)-c]}" -le $# ]]; then + zparseopts -E c=clear l=list + + if [[ -n "$clear" ]]; then + # if -c provided, clobber the history file echo -n >| "$HISTFILE" echo >&2 History file deleted. Reload the session to see its effects. - elif [[ "${@[(i)-l]}" -le $# ]]; then + elif [[ -n "$list" ]]; then + # if -l provided, run as if calling `fc' directly builtin fc "$@" else + # otherwise, call `fc -l 1` to show all available + # history (and pass additional parameters) builtin fc "$@" -l 1 fi } From 9f2f22d953acc62a2a0ba5f08a746e47be3a6d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 22 Apr 2018 15:25:30 +0200 Subject: [PATCH 7/8] Remove duplicate option append_history The option inc_append_history already has the same effect. --- lib/history.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/history.zsh b/lib/history.zsh index 23e96c9d..8a1bc010 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -32,7 +32,6 @@ HISTSIZE=10000 SAVEHIST=10000 ## History command configuration -setopt append_history # append history to HISTFILE on session exit setopt extended_history # record timestamp of command in HISTFILE setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE setopt hist_ignore_dups # ignore duplicated commands history list From 2589cdd8f9603d03f5b84aab57fda96ac0259f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Sun, 22 Apr 2018 15:26:57 +0200 Subject: [PATCH 8/8] Increment HISTSIZE to fix hist_expire_dups_first This fixes the old behavior which made it so all duplicates would be deleted if the command history filled up with unique events. > You should be sure to set the value of HISTSIZE to a larger number > than SAVEHIST in order to give you some room for the duplicated > events, otherwise this option will behave just like HIST_IGNORE_ALL_DUPS > once the history fills up with unique events. --- lib/history.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/history.zsh b/lib/history.zsh index 8a1bc010..7d4e59d0 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -28,7 +28,7 @@ esac ## History file configuration [ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" -HISTSIZE=10000 +HISTSIZE=50000 SAVEHIST=10000 ## History command configuration