Partners, are you looking for an alternative to Bash? Are you looking for a tool that is easier to use? Then, don't hesitate anymore. After seeing this article, you have already found the "dream" answer.
Fish (short for Friendly Interactive Shell) is an intelligent and user-friendly command-line shell that can run on Linux, macOS, and other operating systems. It can be used for daily terminal operations and script writing. Compared to bash scripts with the same functionality, scripts written in fish are easier to understand.
Fish's user-friendly features:
- Fish generates suggested commands based on what you have previously typed. This can improve the efficiency of frequently typing the same commands.
- Reasonable script writing
It avoids using obscure and difficult-to-understand characters, thus providing clearer and more friendly syntax.
- Manual page-based auto-completion:
Fish automatically completes parameters based on the command's manual page.
- Fish's syntax highlighting feature
highlights command syntax, making it easier to read and understand.
Installation Method
Below, the installation method under Fedora Workstation is mainly introduced.
Use the dnf command to install fish:
$ sudo dnf install fishInstall the util-linux-user package, and then run the chsh (i.e., change shell) command with appropriate parameters to set fish as the default shell:
$ sudo dnf install util-linux-user$ chsh -s /usr/bin/fishYou need to log out and log back in for the changes to take effect.
Since this is not a graphical user interface application, you need to use rpm-ostree for layered installation. Use the following command to install fish on Fedora Silverblue:
$ rpm-ostree install fishOn Fedora Silverblue, you need to reboot to switch to the new ostree image.
If you want to set fish as the main shell on Fedora Silverblue, the simplest way is to update the /etc/passwd file. Find your user and change /bin/bash to /usr/bin/fish.
Then you need root privileges to edit the /etc/passwd file. Again, you need to log out and log back in for the changes to take effect.
The fish user configuration file is located at ~/.config/fish/config.fish. To make configuration changes for all users, edit /etc/fish/config.fish.
Each user's configuration file must be created manually. The installation script will not create the ~/.config/fish/config.fish file.
Here are some configuration examples and their corresponding bash scripts for quick use:
Create aliases
- ~/.bashrc:
alias ll='ls -lh'
- ~/.config/fish/config.fish:
alias ll='ls -lh'
Set environment variables
- ~/.bashrc:
export PATH=$PATH:~/bin
- ~/.config/fish/config.fish:
set -gx PATH $PATH ~/bin
Interacting with fish
If fish is configured as the default shell, the command prompt will look similar to the image below. If fish has not been configured as the default shell, simply run the fish command to start it in the current terminal session.
When you start typing a command, you will notice syntax highlighting:
Cool, right? 🙂
While typing, the system will also provide command suggestions. For example, typing the previous command again:
Notice the gray text that appears when typing. These gray texts are prompt information, representing the command you previously entered. To auto-complete, just press CTRL+F.
Type a hyphen (-) and then press the Tab key to get parameter suggestions based on the manual page of the preceding command:
Press the TAB key once to display the first few suggestions (if there are only a few arguments, all suggestions will be displayed). Press the TAB key again to display all suggestions. Press the TAB key three times in a row to switch to interactive mode, where you can use the arrow keys to select arguments.
Make Fish More Powerful
Use Powerline to make Fish's functions even more powerful. It adds many features to Fish's interface, such as command execution time, colored Git status, and current Git branch.
Before installing Powerline for Fish, you must first install Oh My Fish. Oh My Fish extends Fish's core infrastructure, allowing it to install other plugins. The easiest way to install Oh My Fish is to use the curl command:
curl -L https://get.oh-my.fish | fishIf you don't want to pipe the installation command directly to curl, please refer to the installation section in Oh My Fish's README file to understand its installation method.
Fish's powerline plugin is bobthefish. Bobthefish requires the powerline-fonts package.
On Fedora Workstation:
sudo dnf install powerline-fontsOn Fedora Silverblue:
> rpm-ostree install powerline-fontsOn Fedora Silverblue systems, you need to reboot the system to complete the font installation.
After installing the powerline-fonts package, install bobthefish:
> omf install bobthefishNow, you can experience the full fun of fishing through Powerline:
Conclusion
fishshell.com recently released fish version 4.3, an interactive Shell.
This version improves theme settings to be smarter and enhances auto-completion and terminal integration. In addition, it has made numerous changes to scripting and interactive features, along with various enhancements and improvements, while also improving stability.
Fish's GitHub:
https://github.com/fish-shell/fish-shell
Compiled by: Luoyi
Related Reading:
Google launches AI command-line coding tool, straight to Shell
Linux: How the kernel interacts with hardware
Why 90% of microservices are still like monolithic applications?