#zsh #shell-history #command #finding #linux

app ristory

A tool for finding history zsh commands

8 releases

0.1.7 Jun 8, 2023
0.1.6 Feb 27, 2023
0.1.5 Sep 19, 2022
0.1.2 Aug 24, 2022

#13 in #finding

50 downloads per month

MIT license

14KB
284 lines

ristory

Crates.io version

a tool for finding zsh history command 😀

Install

1. 安装 Rust

安装 Rust 可以参考文档:https://rustwiki.org/zh-CN/book/ch01-01-installation.html ,如果开发环境是 Linux 或 macOS 可以直接执行

$ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

安装成功后会出现

Rust is installed now. Great!

验证 Rust 环境已经成功安装,在 Shell 中输入

$ rustc --version

看到最新发布的稳定版本的版本号、提交哈希值和提交日期,如下所示格式:

rustc x.y.z (abcabcabc yyyy-mm-dd)

就说明 Rust 环境安装成功了。

2. 安装 ristory

直接使用 Rust 包管理工具(Cargo)安装,执行

$ cargo install ristory

3. 将 ristory 作为 zsh 插件

将当前仓库下,shell/ristory.zsh 脚本添加到 .zshrc 文件中

autoload -U add-zsh-hook

_ristory() {
	emulate -L zsh
	zle -I

	echoti rmkx
	output=$(ristory 3>&1 1>&2 2>&3)
	echoti smkx

	if [[ -n $output ]] ; then
		LBUFFER=$output
	fi

	zle reset-prompt
}

zle -N _ristory_widget _ristory

if [[ -z $RISTORY_NOBIND ]]; then
	bindkey '^h' _ristory_widget
fi

其中,bindkey 为绑定 ristory 的 zsh 快捷键,可以修改为任何你喜欢的按键;

使用帮助

ristory 目前支持多关键词搜索,通过 '&' 来分割关键词,比如输入 "a&b",就会在 zsh_history 中搜索出所有包含 a 和 b 关键词的命令行。

Dependencies

~6–16MB
~253K SLoC