Wayland clipboard manager with support for multimedia
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 4 个月前 | ||
| 11 个月前 | ||
| 10 个月前 | ||
| 10 个月前 | ||
| 4 年前 | ||
| 2 个月前 | ||
| 5 个月前 | ||
| 11 个月前 | ||
| 11 个月前 | ||
| 5 个月前 | ||
| 10 个月前 |
cliphist
适用于 Wayland 的剪贴板历史“管理器”
- 将剪贴板变更写入历史文件。
- 通过 dmenu、rofi、wofi(或任何您喜欢的选择器)调用历史记录。
- 同时支持 文本 和 图片。
- 剪贴板内容 按字节精确 保留。
- 前导/尾随空白、无空白或换行符均会保留。
- 不会破坏诸如 Vim 的单词、行或块模式等高级编辑器选择。
- 无选择器概念,仅通过管道操作。
需要 Go、wl-clipboard、xdg-utils(用于图片 MIME 类型推断)。
安装
- 如果您的发行版仓库中有,您可以尝试使用 发行版仓库。
- 或者从 发布页面 下载静态二进制文件,并将其放置在
$PATH中的某个位置。 - 或者使用 Go 从源代码安装:
$ go install go.senan.xyz/cliphist@latest。
使用方法
监听剪贴板变更
$ wl-paste --watch cliphist store
此命令将监听主剪贴板的变更并将其写入历史记录。
每个会话调用一次即可——例如,在您的 Sway 配置中。
选择历史项目
$ cliphist list | dmenu | cliphist decode | wl-copy
将此命令绑定到您键盘上的便捷按键。
删除历史项目
$ cliphist list | dmenu | cliphist delete
或者手动查询删除:
$ cliphist delete-query "secret item"。
清空数据库
$ cliphist wipe。
压缩数据库
$ cliphist compact。
选择器示例
dmenu
cliphist list | dmenu | cliphist decode | wl-copy
fzf
cliphist list | fzf --no-sort | cliphist decode | wl-copy
rofi(dmenu 模式)
cliphist list | rofi -dmenu | cliphist decode | wl-copy
fuzzel(dmenu 模式)
cliphist list | fuzzel --dmenu | cliphist decode | wl-copy
rofi(带图片的自定义模式)
rofi -modi clipboard:/path/to/cliphist-rofi-img -show clipboard -show-icons
wofi
cliphist list | wofi -S dmenu | cliphist decode | wl-copy
Sway 的示例配置:
exec wl-paste --watch cliphist store
bindsym Mod1+p exec cliphist list | wofi -S dmenu | cliphist decode | wl-copy
FAQ
为什么我的选择器中会有数字?我能去掉它们吗?
将以数字为前缀的行通过管道传递给 cliphist decode 是很重要的。这个数字用于在数据库中查找您所做的确切原始选择,并保留所有前导、尾随、不可打印等空白字符。这些内容都不会显示在 cliphist list 的预览输出中。
由于 cliphist list 的格式是 "<id>\t<100 字符预览>",并且大多数选择器会将 "\t" 视为列分隔符,您可以尝试只选择第 2 列。
# fzf
cliphist list | fzf -d $'\t' --with-nth 2 | cliphist decode | wl-copy
# rofi
cliphist list | rofi -dmenu -display-columns 2 | cliphist decode | wl-copy
# fuzzel
cliphist list | fuzzel --dmenu --with-nth 2 | cliphist decode | wl-copy
# wofi
# It kind of works but breaks with quotes in the original selection. I recommend not trying to hide the column with wofi.
cliphist list | wofi --dmenu --pre-display-cmd "echo '%s' | cut -f 2" | cliphist decode | wl-copy
如何筛选复制到 cliphist 的项目,或始终复制浏览器中的图片?
也可以针对多种 MIME 类型多次运行 wl-paste --watch。
例如,在窗口管理器的启动项中,你可以运行:
wl-paste --type text --watch cliphist store
wl-paste --type image --watch cliphist store
现在,你的历史记录中应该已有文本和原始图像数据。同时请确保已安装 xdg-utils。
打包
演示
https://user-images.githubusercontent.com/6832539/230513908-b841fffe-d7d5-46c2-b29f-28b3e91daa74.mp4
配置
cliphist 可通过可选配置来扩展默认功能。任何选项都可以通过 CLI 参数、环境变量或配置文件键提供。
例如,max-items 选项可以通过 CLI 设置为 -max-items 100,通过环境变量设置为 CLIPHIST_MAX_ITEMS=100,或在配置文件中设置为 max-items 100。
如果选择使用配置文件,默认位置为 $XDG_CONFIG_HOME/cliphist/config。文件格式为文本文件,每行一个选项,格式为 <键> <值>。例如:
# example cliphist config
max-items 1000
max-dedupe-search 200
可用选项列表如下:
| CLI 参数 | 环境变量 | 配置文件键 | 描述 |
|---|---|---|---|
| -max-dedupe-search | CLIPHIST_MAX_DEDEUPE_SEARCH | max-dedupe-search | (可选)查找重复项时要检查的最近项目最大数量(默认值 100) |
| -max-items | CLIPHIST_MAX_ITEMS | max-items | (可选)要存储的项目最大数量(默认值 750) |
| -max-store-size | CLIPHIST_MAX_STORE_SIZE | max-store-size | (可选)要存储的剪贴板项目最大大小,例如 5MB、10MiB、1GB(默认值 5MB) |
| -min-store-length | CLIPHIST_MIN_STORE_LENGTH | min-store-length | (可选)要存储的最小字符数 |
| -preview-width | CLIPHIST_PREVIEW_WIDTH | preview-width | (可选)预览的最大字符数(默认值 100) |
| -db-path | CLIPHIST_DB_PATH | db-path | (可选)数据库路径(默认值 $XDG_CACHE_HOME/cliphist/db) |
| -config-path | CLIPHIST_CONFIG_PATH | (可选)配置文件路径(默认值 $XDG_CONFIG_HOME/cliphist/config) |