Fish and Atuin usage notes

I have read articles related to fish shell many years ago, because I have been using zsh + Oh My Zsh all year round and I feel it is very smooth and there is no motivation to switch. Until one day I suddenly wanted to try fish. I have been using it for several months and I feel very good about it.

Only on behalf of personal views:

1. Advantages

  • Completion and prompts are more powerful than zsh. I almost use native fish without any additional configuration. Sometimes the prompts that pop up give people a feeling of AI blessing.

Switch to a certain directory and run a certain command, and it will always prompt correctly.

As shown in the picture below, I switched to the source code directory of wine and prepared to recompile. As soon as I entered a point, the full name command was prompted. At this time, pressing Ctrl + f or the 'right arrow key' will automatically complete the command.

fish-suggests

For another example, if you enter ip + space and then press tab, the sub-options of the ip command will pop up. To be honest, the ip command is very complicated now, and the elderly and infirm cannot remember it. This kind of prompt is very considerate.

ip-suggests

It’s not over yet, continue reading, enter ip link with a space and tab, and the sub-commands and core prompts will be displayed together. Of course, the history completion is also there, you can choose.

ip-link-suggests

I have to say that this kind of reminder is convenient enough and can improve a lot of efficiency in daily work.

  • It's fast, anything that slows it down is annoying.

The built-in functions of native fish are enough to handle various daily operations, and there is no need for blessings such as Oh My Zsh. Running naked is healthier.

  • Simple configuration

Enter 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.

You can configure colors, prompt, etc. on the web page that pops up in the default browser

fish-config

Type help

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

The browser pops up the file:///usr/share/doc/fish/index.html offline document.

fish-doc-offline

2. Disadvantages

  • Poor compatibility

For example, to activate the python virtual environment, you need to do this:

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

It doesn’t seem to be very troublesome, after all, it comes with the activate.fish script.

Some shell scripts cannot be run directly. Generally, when encountering this situation, I will run the bash command and switch temporarily.

There is no way, the shell that comes with most systems is bash.

No other inconveniences have been discovered yet.

In short, I personally think that fish shell is very suitable for use on private computers. It is fast and convenient. After using it for a few months, I will not know how to use zsh for the time being.

3. Use atuin to manage shell history

I experienced this project of atuin once a long time ago, and it seemed to be taking a big step at the beginning. The main thing is that it takes over the up key by default, which is hard to get used to.

As for how to install and use atuin, I won’t write about it here. There are many online tutorials and they are very simple.

I don't use its cloud synchronization function. It is impossible to hand over history records to a third party for storage these days. Although it is encrypted and secure and no one can see it, it is better to keep personal data in your own hands.

If cloud synchronization is not enabled, the default data is stored in SQLite, and the data structure is as follows:

atuin-history

It records when, what command was executed, exit status code, working directory, host name, etc.

You can import the history records of other shells. There is no test whether repeated imports will remove duplicates.

 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!

Importing the history records of various other shells is equivalent to having a portable history database.

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

As long as you save this database file, you can retrieve the history records even if you buy a new computer. This is really the conscience of the industry.

4. Unbind the direction keys of atuin under fish

I don’t know what other people think, but I personally tend to use the shell’s arrow key function. Just search and bind ctrl + r with atuin. After all, whether it is zsh or fish, search is still not as powerful as atuin.

fish Disable the direction disk binding (Disable up arrow) setting below:

 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

This setting needs to be explored through the documentation. There are only zsh examples in the official documentation.

Why does it work? Watch the last part here:

 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

Detection variable ATUIN_NOBIND is the string "true" and the length is not 0

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

The various operations in if will not be bound, and will naturally execute your own settings.

After such configuration, you can use the default direction key function without overdoing the span, and you can also centrally manage history and use the more advanced autin search function (ctrl + r trigger), which is good.

atuin icon:

atuin-search

For more functions of atuin, you can view its documentation.

Lastmod: Tuesday, January 30, 2024

See Also:

Translations: