惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
The Cloudflare Blog
S
SegmentFault 最新的问题
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
量子位
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
V2EX
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
J
Java Code Geeks
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI

mephisto.cc

修复rime-ice无法弹出候选框的问题 开机滚动字体显示优化 个人网站安全防护 树莓派上部署Vaultwarden 使用goaccess实时分析Caddy日志 个人网站监控 Hugo全站AVIF记 Linux下尝试使用Godot开发小游戏 Arch linux dae 透明代理 Airflow接管galler-dl下载任务 如何使用gallery-dl批量下载图像 Arch核显下如何愉快玩Dota2和CS2 Arch/labwc 环境网络相关设置 Rime添加dota2词库 Arch 重装记录 Supertuxkart iOS版终于发布了 打造自己的流媒体音乐服务 剪切板管理工具clipcat推荐 MangoHud性能监控 微信小程序开发记 Rofi试用 解决Arch下VSCode无法输入中文的问题 独立窗口管理器下无法录屏问题处理 上海市二手房成交数据监控 OpenLDAP监控 Arch linux如何顺畅连接蓝牙设备 使用Git和Ansible管理配置文件 Arch Linux SSL VPN 客户端配置 简单获取celery任务实时结果 Arch linux下iNode客户端的安装和使用方法
Fish 和 Atuin使用记
2024-01-30 · via mephisto.cc

很多年前就看过 fish shell 相关文章,因为常年使用 zsh + Oh My Zsh 觉得很顺畅,没什么动力切换。直到某一天突然想试试 fish,陆续使用了几个月,个人感觉很不错。

仅代表个人观点:

1. 优势

  • 补全、提示比 zsh 强大,我几乎是使用原生 fish,没什么额外配置,有时候冒出的提示给人一种 AI 加持的感觉。

切换到某个目录运行某个命令,它总能正确提示。

如下图所示,我切换到 wine 的源码目录,准备重新编译,才输入一个点,就已经提示出完整名命令,此时按 Ctrl + f 或者 '右方向键'会自动补全

fish-suggests

再比如,你输入 ip + 空格,再按 tab,会弹出 ip 命令的子选项,老实说现在 ip 命令很复杂,年老体弱各种记不住,这样的提示可谓非常贴心了。

ip-suggests

还没完,接着看,输入 ip link 空格加 tab,连子命令和核心提示一并显示出来了,当然历史补全也还在,任君选择。

ip-link-suggests

不得不说,这种提示够方便,日常工作能提升不少效率。

  • 速度快,一切拖慢运行速度的东西都会让人生厌。

原生 fish 自带的功能,足够应付日常各种操作,根本不需要 Oh My Zsh 等加持,裸奔更健康。

  • 配置简单

输入 fish_config

1➜  ~ fish_config
2Web config started at file:///tmp/web_config22yhky5b.html
3If that doesn't work, try opening http://localhost:8000/af9321754796589c755386f704c81785/
4Hit ENTER to stop.

在默认浏览器弹出的 web 页面上即可配置 colorsprompt

fish-config

输入 help

1➜  ~ help
2help: Help is being displayed in xdg-open.

浏览器弹出 file:///usr/share/doc/fish/index.html 离线文档。

fish-doc-offline

2. 劣势

  • 兼容性不好

比如激活 python 的虚拟环境,需要这样:

1➜  google-api-python-client . .venv/bin/activate.fish
2(.venv) ➜  google-api-python-client

好像也不是很麻烦,毕竟带有 activate.fish 脚本。

部分 shell 脚本无法直接运行,一般遇到这种状况我会运行 bash 命令,临时切换。

没办法,大部分系统自带的 shell 都是 bash。

其它不方便的地方目前还没有发现。

总之,我个人认为,fish shell 很适合在私人电脑上使用,快捷方便,使用几个月后,暂时是不会切会 zsh 了。

3. 使用 atuin 管理 shell 历史

atuin 这个项目很早前我体验过一次,一开始貌似步子迈大了。主要是它默认接管向上键,这一点很难适应。

至于怎么安装使用 atuin,这里不写,网上教程很多,也很简单。

我不用它的云同步功能,这年头不可能把 history 记录交给第三方存储,虽然说加密安全,谁也看不到,个人数据还是掌控在自己手上比较好。

不开启云同步,默认数据是存在 SQLite 里面的,数据结构如下所示:

atuin-history

里面记录了什么时候、执行了什么命令、退出状态码、工作目录、主机名等。

可以导入其它 shell 的历史记录,重复导入会不会去重,没有测试。

 1➜  ~ atuin import zsh
 2        Atuin
 3======================
 4          🌍
 5       🐘🐘🐘🐘
 6          🐢
 7======================
 8Importing history...
 9Importing history from zsh
10Import complete!
11➜  ~ atuin import bash
12        Atuin
13======================
14          🌍
15       🐘🐘🐘🐘
16          🐢
17======================
18Importing history...
19Importing history from bash
20Import complete!

导入其它各种 shell 的历史记录,相当于拥有了一个便携 history 数据库。

1➜  ~ file ~/.local/share/atuin/history.db
2/home/mephisto/.local/share/atuin/history.db: SQLite 3.x database, last written using SQLite version 3038002, writer version 2, read version 2, file counter 72, database pages 966, cookie 0x4, schema 4, UTF-8, version-valid-for 72

只要保存好这个数据库文件,假设买了个新电脑,都可以找回 history 记录,真是业界良心啊。

4. fish 下解除 atuin 的方向键绑定

不知道其它人感觉怎么样,反正我个人倾向于使用 shell 的方向键功能,atuin 搜索绑定 ctrl + r就好。毕竟不管是 zsh 还是 fish,搜索还是没有 atuin 强大的。

fish 下面解除方向的盘绑定(Disable up arrow)设置:

 1➜  fish pwd
 2/home/mephisto/.config/fish
 3➜  fish cat config.fish
 4if status is-interactive
 5    # Commands to run in interactive sessions can go here
 6   set -gx ATUIN_NOBIND "true"
 7   atuin init fish | source
 8   bind \cr _atuin_search
 9end
10
11function fish_greeting
12end

这份设置需要看文档摸索下的,官方文档上只有 zsh 示例。

为什么它能工作呢?看这里的最后一部分:

 1➜  ~ atuin init fish
 2set -gx ATUIN_SESSION (atuin uuid)
 3
 4function _atuin_preexec --on-event fish_preexec
 5    set -gx ATUIN_HISTORY_ID (atuin history start "$argv[1]")
 6end
 7
 8function _atuin_postexec --on-event fish_postexec
 9    set s $status
10    if test -n "$ATUIN_HISTORY_ID"
11        RUST_LOG=error atuin history end $ATUIN_HISTORY_ID --exit $s &
12        disown
13    end
14end
15
16function _atuin_search
17    set h (RUST_LOG=error atuin search -i (commandline -b) 3>&1 1>&2 2>&3)
18    commandline -f repaint
19    if test -n "$h"
20        commandline -r $h
21    end
22end
23
24if test -z $ATUIN_NOBIND
25    bind \cr _atuin_search
26    bind -k up _atuin_search
27    bind \eOA _atuin_search
28    bind \e\[A _atuin_search
29
30    if bind -M insert > /dev/null 2>&1
31        bind -M insert \cr _atuin_search
32        bind -M insert -k up _atuin_search
33        bind -M insert \eOA _atuin_search
34        bind -M insert \e\[A _atuin_search
35    end
36end

检测变量 ATUIN_NOBIND 为字符串 “ture”,长度不为 0

-z STRING Returns true if the length of STRING is zero.

if 里面的各种操作不会绑定,自然就是执行你自己的设定了。

这样一番配置后,既可以使用默认的方向键功能,不至于跨度过大,又能集中管理 history,使用更加高级的 autin 搜索功能(ctrl + r触发),不错的。

atuin 图示:

atuin-search

更多 atuin 的功能,可以查看它的文档。