history-watcher
is a tool designed to optimize and enhance the command history experience in bash/zsh by addressing common issues faced by power users. This tool aids in efficiently searching through a large command history by integrating with other fuzzy finders.
- Performance: Improves the speed of history retrieval in bash when dealing with extensive history records.
- Duplicates: Eliminates the clutter of repeated commands in your history to streamline the search process.
Install history-watcher
by running the following command:
go install github.com/minoritea/history-watcher@latest
To use history-watcher
, perform the following steps:
- Install a fuzzy finder like
peco
orfzf
. - Launch
history-watcher
as a background service. goemon is a useful tool for managing background services.goemon -- history-watcher
- Define a function in your
.bashrc
to interact withhistory-watcher
using the chosen fuzzy finder:function hp() { local action action=$(curl -N -s localhost:14444 | peco) READLINE_LINE="${action}" READLINE_POINT="${#READLINE_LINE}" } bind -x '"\C-r": hp' bind '"\C-xr": hp'
- Retrieve your history using the regular bash history shortcut keys.
- Install a fuzzy finder like
peco
orfzf
. - Launch
history-watcher
as a background service. goemon is a useful tool for managing background services.goemon -- env HW_HISTFILE_FORMAT=zsh_extended history-watcher
- Define a function in your
.zshrc
to interact withhistory-watcher
using the chosen fuzzy finder:function __search_history() { BUFFER=`curl -N -s localhost:14444 | peco` CURSOR=$#BUFFER zle reset-prompt } zle -N __search_history bindkey '^R' __search_history
- Retrieve your history using the regular zsh history shortcut keys.
history-watcher monitors the .bash_history file, captures command history, and stores it in an ordered set sorted by the last execution time. Therefore, it retains command history without duplication as long as it is the same command invocation. It also provides an HTTP endpoint, so when accessed from an HTTP client, it returns the stored command history. history-watcher includes all command history in the HTTP response, but it returns them in ascending order as a stream. This allows you to start narrowing down and selecting results without waiting for the retrieval of all results by combining it with a fuzzy finder that supports stream input.
You can change the behavior of the tool by defining the following environment variables:
- HW_HOST: The address on which the server binds(default: 127.0.0.1)
- HW_PORT: The port number on which the server binds(default: 14444)
- HW_TOKEN: Required for authentication token for retrieving command history(default: NONE)
- HW_DB_FILE: Persists command history to a file or database(default: ~/.cache/history-watcher.db)
- to disable persistence, set HW_DB_FILE to
-
- to disable persistence, set HW_DB_FILE to
- HW_HISTFILE: Shell's history file(default: ~/.bash_history, when zsh or zsh_extended is specified as HW_HISTFILE_FORMAT, ~/.zsh_history)
- HW_HISTFILE_FORMAT: Shell's history file format(default: bash)
- bash: Default format.
- zsh: Zsh's history file format.
- zsh_extended: Extended Zsh's history file format.
- HW_POLL: Polls the .bash_history file for monitoring(default: false)
history-watcher
is licensed under the GNU General Public License v3.0.
Feel free to contribute to the project, report issues, or suggest improvements on GitHub.