Some time ago, I noticed that Teacher Ruan updated a blog, which introduced a shell — fish. After trying it out for yourself, I found it really recommended and was ready to use it as a workhorse shell instead of ZSH.





The index

  • introduce
  • Install (click here for hot tofu)

introduce

Why did you abandon ZSH for Fish

  • ZSH has been my workhorse shell for a long time and there’s nothing I can’t do, so why would I want to get rid of it? This is not a love affair. It’s not that ZSH is bad, it’s that fish is too good. After a brief trial run, I decided to keep it. Because the experience is so smooth and smooth.

  • Here are some of the most intuitive feelings.

1. Automatic completion and automatic suggestion

  • ZSH does have powerful autocomplete commands. But it’s nothing compared to fish. In addition to automatic completion, fish commands also mark the correctness of commands, and the correctness of input commands can be clearly displayed by color. The color contrast may not be obvious because of the color scheme, but you can still see that red clearly indicates the invalid command.

  • The following diagram shows a valid command:

  • Careful friends may also have spotted the full command in gray. This is an automatic recommendation from FISH. Here’s a picture that might be more intuitive (click to see a larger version) :

  • Although ZSH has the ability to blur the match history commands, it’s clear that fish’s thoughtfulness in knowing what to do as soon as you type the first letter makes the user experience significantly better. Like a good girlfriend, a good sister.

  • In addition, fish can also identify invalid commands while matching historical commands. Red highlights:

The efficiency of 2.

  • One reason to use a terminal shell is efficiency. I am sometimes asked why I use the command line when I have git graphical tools. I thought about it and found that while graphical tools were intuitive, they were slow compared to the command line, and many of the commands didn’t support them.

  • So if the purpose of using a shell is to improve efficiency, how can you tolerate a shell that is extremely slow? Here are two graphs that clearly illustrate the efficiency of each:


  • You can see both of these results by pressing the Enter key consecutively in both shells. The former is fish and the latter is ZSH. It can be seen that the latter has obvious lag. Perhaps it’s because ZSH is so powerful and has so many features that it runs so slowly. It finally became unbearable.

summary

  • For me personally, the above two points are enough to switch from ZSH to FISH. Other people may have their own opinions, but I haven’t found anything upsetting about fish so far, so I’ll keep using it for a while.

Installation and use

The installationfish

  • In macOS, there are many ways to install, here is a list of homebrew installation, very easy.
$ brew install fishCopy the code
  • Once installed, type in Fish and start a whole new adventure.

  • If you can’t wait to make it the default shell:

chsh -s /usr/local/bin/fishCopy the code
  • If you are prompted that fish is not the standard shell, run the following command to add fish to the default shells. Run the command Settings above again.
echo /usr/local/bin/fish | sudo tee -a /etc/shellsCopy the code
  • After that, restart your iterm/terminal and you’ll see the new fish shell!

use

  • Fish’s basic configuration in ~ /. Config/fish/config. The fish in the file. If you do not have this file after installing fish, you can create a new one.

  • Fish allows you to change configuration files on the web UI. Run fish_config to view.

  • You can set the fish greeting by changing the following configuration, which is output each time you enter.

set fish_greeting 'Talk is cheap. Show me the code.'Copy the code
  • ZSH has many useful aliases, as does fish. The quickest way to do this is to type it directly into a configuration file. Here is my Git alias.

  • If you’re on the front end like me, you probably use NVM to manage Node.fish, too. There’s no tool available, but you can change the configuration to make it work.
bass source ~/.nvm/nvm.shCopy the code
  • Maybe you have the Thefuck plugin installed in ZSH, and yes, you can use it in Fish.
eval(thefuck --alias | tr '\n' '; ') alias fuck-it='export THEFUCK_REQUIRE_CONFITMATION=True; fuck; export THEFUCK_REQUIRE_CONFIRMATION=False'Copy the code
  • Maybe you have the Autojump plugin installed, and yes, it can be used here as well. Add the following code:
begin
  set --local AUTOJUMP_PATH $HOME/autojump/bin/autojump.fish
  if test -e $AUTOJUMP_PATH
    source $AUTOJUMP_PATH
  end
endCopy the code
  • This is mainly to check the autojump.fish file. The path pair takes effect.

  • Brew install thefuck, brew Install autojump if the two plugins are not already installed.

Some tools

oh my fish
  • And ZSHoh my zshFish, toooh my fish. You can run the following command on the terminal to install:
curl -L https://get.oh-my.fish | fishCopy the code
  • oh my fishBy running theomf install [<name>/<url>]To install the plug-in. Such as runningomf install oceanInstall themes.
    • omf list: lists the packages currently installed.
    • omf theme <theme>: Lists all themes/applies a theme.
    • omf remove <name>: Removes a packet.
fisherman
  • Fisherman also has a plug-in management tool. Fisherman is installed directly on the terminal by running the following command:
curl -Lo ~/.config/fish/functions/fisher.fish --create-dirs git.io/fisherCopy the code
  • fishermanBy running thefisher <name>Install the plug-in. Such as runningfisher z.
    • fisher ls: View the current plug-in.
    • fisher ls-remote: View all plug-ins.
    • fisher rm <name>: Remove the plug-in.

conclusion

  • That’s my record and basic tutorial on using Fish. There’s actually a lot more to explore, but so far there’s no problem for everyday use. Hope you can also feel happy in the process of using fish!