鱼鱼抓图
I’ve been using the Fish Shell for months, and I think it’s the best shell I ever used. For many reasons.
我已经使用鱼壳几个月了,我认为这是我使用过的最好的壳。 因为许多的原因。
People seem to stick with Bash which is the default on many systems (update: now the macOS default is Zsh) or use Zsh, with a great tool like Oh My Zsh to make it even more amazing.
人们似乎坚持使用Bash ,这是许多系统上的默认设置(更新:现在,macOS默认是Zsh)或使用Zsh,并使用了类似Oh My Zsh这样的强大工具,使其更加出色。
Bash, while great, is a very basic shell, with a limited set of configurable options. I tend to use it mostly to run Bash scripts (which are another topic) rather than as an interactive shell. Zsh offers a lot of features but requires a little bit of configuration to set up, which might frighten beginners. Also, too many options and freedom means you can get in a configuration paralysis pretty easily, and you end up changing the options 20 times in a week to make sure you’re not missing out.
Bash虽然很棒,但它是一个非常基本的外壳,带有一组有限的可配置选项。 我倾向于将其主要用于运行Bash脚本 (这是另一个主题),而不是用作交互式shell。 Zsh提供了许多功能,但需要进行一些配置才能设置,这可能会使初学者感到恐惧。 另外,太多的选项和自由度意味着您很容易陷入配置瘫痪状态,最终一周要更改20次选项,以确保您不会错过。
I don’t want to “bash” on those projects, which are amazing and I used for a lot of time and sometimes still use. This description is my attempt at highlighting the benefits of Fish
我不想在那些项目上“扑朔迷离”,这太了不起了,我花了很多时间,有时仍然使用。 这个描述是我试图强调鱼的好处
Fish Shell to the rescue! This shell provides an amazing environment, and fully featured configuration out of the box.
鱼壳来抢救! 该外壳提供了一个令人惊叹的环境,并且具有开箱即用的全功能配置。
My favorite features of Fish are:
Fish最喜欢的功能是:
- it has a better autocomplete features for commands you already executed and this alone is really making my day to day faster and less stressful. 它为您已经执行的命令提供了更好的自动完成功能,仅此一项就可以使我的日常工作更快,更省力。
you begin typing a command and press the
up
key to see all the times in the shell history where you used that command before.您开始输入命令并按
up
键以查看Shell历史记录中您以前使用该命令的所有时间。- you can install Fish on any system and it works in the same way everywhere, without having to customize too much to get the fancy things. 您可以在任何系统上安装Fish,并且Fish可以在任何地方以相同的方式工作,而不必进行过多的自定义来获得精美的东西。
When it comes to scripting, it is fairly different from Bash scripting (in a better way IMHO), but you can run any Bash script provided it is prefixed with #!/bin/bash
.
在脚本方面,它与Bash脚本(以更好的恕我直言)完全不同,但是您可以运行任何以#!/bin/bash
为前缀的Bash脚本。
Right after the installation you get those nice things:
安装完成后,您将获得以下好处:
- syntax highlighting 语法高亮
- a nice prompt 一个很好的提示
- autocompletion 自动补全
- parameter suggestion with man page hints 手册页提示的参数建议
- web-based configuration 基于Web的配置
and in my opinion is the most beginner friendly shell.
我认为这是最适合初学者的外壳。
One of the funny things I remember I noticed was the homepage. At first I could not understand if that was some sort of relic from the past:
我记得我注意到的有趣的事情之一是主页。 起初,我不明白这是否是过去的遗物:
For those lucky few with a graphical computer, you can set your colors and view functions, variables, and history all from a web page.
对于那些拥有图形计算机的幸运儿,您可以从网页上设置颜色并查看功能,变量和历史记录。
Then I realized it was programmer’s humor and it made me chuckle. Tech should always be fun, right?
然后我意识到这是程序员的幽默,这让我发笑。 科技应该总是很有趣,对吗?
首先,什么是壳? (First things first: what is a shell?)
A shell is an interface to the underlying operating system. It allows you to execute operations using text and commands, and it provides users advanced features like being able to create scripts.
Shell是基础操作系统的接口。 它允许您使用文本和命令执行操作,并且为用户提供了高级功能,例如能够创建脚本。
安装 (Installation)
Install Fish by running brew install fish
on macOS.
通过在macOS上运行brew install fish
来安装Fish。
Check out my macOS terminal guide
查看我的macOS终端指南
fish
is installed in /usr/local/bin/fish
.
fish
安装在/usr/local/bin/fish
。
Since that is likely already in your path, run fish
to start the Fish shell (type exit
to return back to your default shell)
由于这很可能已经在您的路径中了,请运行fish
启动Fish Shell(键入exit
返回到您的默认Shell)
组态 (Configuration)
Once nice thing about Fish is a web-based configuration. Run fish_config
to start the web client.
Fish的优点是基于Web的配置。 运行fish_config
启动Web客户端。
From here you can
从这里你可以
- choose a color scheme from a list of predefined ones 从预定义的颜色列表中选择一种颜色方案
- choose a prompt from a list of predefined ones 从预定义的提示列表中选择提示
- inspect the Fish functions and variables configured 检查配置的Fish函数和变量
- see the commands history 查看命令历史
The configuration is stored in the ~/.config/fish
folder, and that’s where you can edit it without having to use the (optional) web based configuration.
该配置存储在~/.config/fish
文件夹中,您可以在其中进行编辑,而不必使用(可选)基于Web的配置。
Fish功能:语法高亮显示,自动完成和带有手册页提示的参数建议 (Fish features: syntax highlighting, autocompletion and parameter suggestion with man page hints)
Fish lets you execute the usual Unix commands available on your system. Filesystem operations, for example:
Fish使您可以执行系统上可用的常规Unix命令。 文件系统操作,例如:
ls
to list filesls
列出文件cd
to change foldercd
更改文件夹rm
to remove a file or folderrm
删除文件或文件夹mv
to move a file to another folder, or change a file namemv
将文件移动到另一个文件夹,或更改文件名cp
to copy a filecp
复制文件
If you run one of those commands (or any
command, really) you will start seeing the words you type get different colors. It makes it really easy to read and understand commands.
如果您运行这些命令之一(或者实际上是any
命令),您将开始看到键入的单词具有不同的颜色。 它使阅读和理解命令变得非常容易。
Fish also adds autocompletion. If you ran cd ~/.config/fish/
previously, and now you type cd
, Fish will suggest commands you might want to type, and you just press the right arrow to accept the suggestion (or you can continue to type to change the command). This suggestion is based on command history and file paths.
鱼还增加了自动补全。 如果您以前运行cd ~/.config/fish/
,现在键入cd
,则Fish会提示您可能要键入的命令,而您只需按向右箭头即可接受建议(或者您可以继续键入以更改命令)。 此建议基于命令历史记录和文件路径。
Suggestions based on autocomplete also work for commands. Here I typed c
and pressed tab:
基于自动完成功能的建议也适用于命令。 在这里,我输入c
并按Tab键:
Fish also suggests parameters and how to use them. Type ls -
and press tab
. A list of the parameters you can use, and their meaning, is shown right below:
鱼还建议参数以及如何使用它们。 输入ls -
并按tab
。 您可以使用的参数及其含义的列表如下所示:
This inline help is generated from man pages, the helpful shell help (try running man ls
for the complete help).
此内联帮助是从手册页 (有用的shell帮助)生成的(尝试运行man ls
以获取完整帮助)。
将Fish设置为默认外壳 (Set Fish as the default shell)
If you like Fish once you try it out and want to make it your default shell, open the file /etc/shells
. I use pico
to do those small file edits, with pico /etc/shells
, but you can use any editor you prefer, even VS Code with code /etc/shells
.
如果您喜欢Fish并尝试将其设置为默认外壳,请打开文件/etc/shells
。 我使用pico
使用pico /etc/shells
进行那些小的文件编辑,但是您可以使用您喜欢的任何编辑器,甚至是带有code /etc/shells
VS Code。
It should contain something similar to:
它应包含类似于以下内容的内容:
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
Add this line at the end to add the Fish shell:
在末尾添加以下行以添加Fish外壳:
/usr/local/bin/fish
next, run
接下来,运行
chsh -s /usr/local/bin/fish
enter your password, and the shell will change for your user.
输入您的密码,外壳将为您的用户更改。
外挂程式 (Plugins)
You can install Fish plugins.
您可以安装Fish插件。
Fisher is a popular Fish package manager.
费舍尔(Fisher)是受欢迎的鱼品包装经理。
Install it using
使用安装
curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
and it’s available with the fisher
command.
它可以通过fisher
命令使用。
Now a package can be installed using fisher add <github-repository-path>
and removed using fisher rm <github-repository-path>
.
现在可以使用fisher add <github-repository-path>
安装软件包,并使用fisher rm <github-repository-path>
删除软件包。
List all plugins installed using fisher ls
.
列出使用fisher ls
安装的所有插件。
Run fisher
to update all the packages you installed.
运行fisher
更新所有已安装的软件包。
Popular plugins are
流行的插件是
edc/bass
make Bash utilities usable in fishedc/bass
使Bash实用程序可在鱼中使用jorgebucaran/fnm
Node.js version managerjorgebucaran/fnm
Node.js版本管理器
Here is a list of packages you can install.
这是您可以安装的软件包列表。
符合POSIX (POSIX compliance)
Various shells comply with the POSIX shell command standard.
各种外壳都符合POSIX Shell命令标准。
POSIX means
POSIX意味着
- Portable 随身携带
- Operating 操作
- System 系统
- Interface 接口
- X (for Unix) X(对于Unix)
and it’s a standard meant to unify the various Unix environment that were built over time. There is a shell command standard subset, which is meant as a way to unify how Unix shells work.
它是一个标准,旨在统一随着时间的推移而构建的各种Unix环境。 有一个shell命令标准子集,它是统一Unix shell如何工作的一种方式。
Unix is a specification/standard for a family of operating systems. Linux and macOS are based on Unix (Windows is not).
Unix是一系列操作系统的规范/标准。 Linux和macOS基于Unix(Windows 不是 )。
bash
, ksh
and others are POSIX compliant. Being POSIX compliant makes scripts written with POSIX compatibility work across POSIX compliant shells.
bash
, ksh
和其他兼容POSIX。 符合POSIX要求使以POSIX兼容性编写的脚本可以在POSIX兼容外壳程序中使用。
Fish (like sh
or csh
for example) is not compliant, so it’s not a POSIX shell, and this means that writing commands and scripts for Fish is different. Scripts written for Fish won’t work outside of Fish. Just like csh
scripts only work on csh (and derivatives)
Fish(例如,如sh
或csh
)不兼容,因此它不是POSIX shell,这意味着为Fish编写命令和脚本是不同的 。 为Fish编写的脚本无法在Fish之外运行。 就像csh
脚本仅适用于csh(及其派生类)一样
Why is it different? Various reasons, but I imagine having to support POSIX means the shell must adhere to a common language that might interfere with the shell philosophy and way of working. Not everyone want to have that baggage of tech to support forever.
为什么不同? 有多种原因,但是我想必须支持POSIX意味着外壳必须遵守可能干扰外壳原理和工作方式的通用语言。 并非每个人都希望拥有如此强大的技术来永远支持。
This will very rarely be a problem with executing commands, but you need to keep it in mind when it comes to scripting and programming.
执行命令很少会出现问题,但是在编写脚本和编程时,请记住这一点。
鱼鱼抓图