很多年前就看过 fish shell 相关文章,因为常年使用 zsh + Oh My Zsh 觉得很顺畅,没什么动力切换。直到某一天突然想试试 fish,陆续使用了几个月,个人感觉很不错。
仅代表个人观点:
切换到某个目录运行某个命令,它总能正确提示。
如下图所示,我切换到 wine 的源码目录,准备重新编译,才输入一个点,就已经提示出完整名命令,此时按 Ctrl + f 或者 '右方向键'会自动补全

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

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

不得不说,这种提示够方便,日常工作能提升不少效率。
原生 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 页面上即可配置 colors 、prompt等

输入 help
1➜ ~ help
2help: Help is being displayed in xdg-open.
浏览器弹出 file:///usr/share/doc/fish/index.html 离线文档。

比如激活 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 了。
atuin 这个项目很早前我体验过一次,一开始貌似步子迈大了。主要是它默认接管向上键,这一点很难适应。
至于怎么安装使用 atuin,这里不写,网上教程很多,也很简单。
我不用它的云同步功能,这年头不可能把 history 记录交给第三方存储,虽然说加密安全,谁也看不到,个人数据还是掌控在自己手上比较好。
不开启云同步,默认数据是存在 SQLite 里面的,数据结构如下所示:

里面记录了什么时候、执行了什么命令、退出状态码、工作目录、主机名等。
可以导入其它 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 记录,真是业界良心啊。
不知道其它人感觉怎么样,反正我个人倾向于使用 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 的功能,可以查看它的文档。
很多年前就看过 fish shell 相关文章,因为常年使用 zsh + Oh My Zsh 觉得很顺畅,没什么动力切换。直到某一天突然想试试 fish,陆续使用了几个月,个人感觉很不错。
仅代表个人观点:
切换到某个目录运行某个命令,它总能正确提示。
如下图所示,我切换到 wine 的源码目录,准备重新编译,才输入一个点,就已经提示出完整名命令,此时按 Ctrl + f 或者 '右方向键'会自动补全

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

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

不得不说,这种提示够方便,日常工作能提升不少效率。
原生 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 页面上即可配置 colors 、prompt等

输入 help
1➜ ~ help
2help: Help is being displayed in xdg-open.
浏览器弹出 file:///usr/share/doc/fish/index.html 离线文档。

比如激活 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 了。
atuin 这个项目很早前我体验过一次,一开始貌似步子迈大了。主要是它默认接管向上键,这一点很难适应。
至于怎么安装使用 atuin,这里不写,网上教程很多,也很简单。
我不用它的云同步功能,这年头不可能把 history 记录交给第三方存储,虽然说加密安全,谁也看不到,个人数据还是掌控在自己手上比较好。
不开启云同步,默认数据是存在 SQLite 里面的,数据结构如下所示:

里面记录了什么时候、执行了什么命令、退出状态码、工作目录、主机名等。
可以导入其它 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 记录,真是业界良心啊。
不知道其它人感觉怎么样,反正我个人倾向于使用 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 的功能,可以查看它的文档。