diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 372681b..b236b12 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -6,7 +6,7 @@ hh --show-configuration >> ~/.bashrc ``` Run `hh --show-configuration` to determine what will be appended to your BASH profile. -This document describes `hh` related configuration in detail - +This document describes `hh` related configuration in detail - [binding hh to a keyboard shortcut](#binding-hh-to-keyboard-shortcut), [colors](#colors), [default history view](#history-view), @@ -35,7 +35,7 @@ Bind `hh` to `Ctrl-r` only if it is interactive shell: if [[ $- =~ .*i.* ]]; then bind '"\C-r": "\C-a hh \C-j"'; fi ``` -To determine the character sequence emitted by a pressed key in terminal, +To determine the character sequence emitted by a pressed key in terminal, type `Ctrl-v` and then press the key. Check your current bindings using: ```bash bind -S @@ -101,20 +101,20 @@ BASH HISTORY SETTINGS --------------------- Use the following BASH settings to get most out of `hh`. -Increase the size of history maintained by BASH - variables defined below increase the +Increase the size of history maintained by BASH - variables defined below increase the number of history items and history file size (default value is 500): ```bash export HISTFILESIZE=10000 export HISTSIZE=${HISTFILESIZE} ``` -Ensure syncing (flushing and reloading) of `.bash_history` with in-memory +Ensure syncing (flushing and reloading) of `.bash_history` with in-memory history: ```bash export PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}" ``` -Force appending of in-memory history to `.bash_history` - (instead of overwriting): +Force appending of in-memory history to `.bash_history` + (instead of overwriting): ```bash shopt -s histappend ``` @@ -124,3 +124,11 @@ Use leading space to hide commands from history: export HISTCONTROL=ignorespace ``` Suitable for a sensitive information like passwords. + +ZSH HISTORY SETTINGS +-------------------- +If you use zsh, set HISTFILE environment variable in ~/.zshrc: + +``` +export HISTFILE=~/.zsh_history +``` diff --git a/INSTALLATION.md b/INSTALLATION.md index 2b1a38d..0a6966e 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -108,12 +108,4 @@ Finish the installation make && make install ``` -ZSH -___ -Set HISTFILE environment variable in ~/.zshrc: - -``` -export HISTFILE=~/.zsh_history -``` - Optionally [configure](CONFIGURATION.md) `hh` and check its [man page](README.md#documentation). diff --git a/src/hstr_history.c b/src/hstr_history.c index 41e77b9..ef99c3d 100644 --- a/src/hstr_history.c +++ b/src/hstr_history.c @@ -79,6 +79,8 @@ HistoryItems *get_prioritized_history() HISTORY_STATE *historyState=history_get_history_state(); int itemOffset = 0; + + // If user use zsh, the name of history file is .zsh_history char* zshFileName = ".zsh_history"; int historyFileLen = strlen(historyFile); int zshFileNameLen = strlen(zshFileName); @@ -90,6 +92,14 @@ HistoryItems *get_prioritized_history() } } if (i == historyFileLen) { + // In zsh history file, the format of item is + // [:][blank][unix_timestamp][:][0][;][cmd] + // Such as: + // : 1420549651:0;ls /tmp/b + // : 1420549680:0;touch /tmp/c + // : 1420549686:0;ln -s /tmp/c /tmp/b + // And the limit of unix timestamp 9999999999 is 2289/11/21, + // so we could skip first 15 chars in every zsh history item to get the cmd. itemOffset = ZSH_HISTORY_ITEM_OFFSET; } }