如何在Linux中安装、配置和使用Fish Shell?

系统 Linux
Bash(全称是 Bourne Again Shell)是运行在今天的大多数 Linux 发行版上的默认的 shell,它非常受欢迎,并具有很多功能。但今天我们将讨论 Fish Shell 。

[[259751]]

每个 Linux 管理员都可能听到过 shell 这个词。你知道什么是 shell 吗? 你知道 shell 在 Linux 中的作用是什么吗? Linux 中有多少个 shell 可用?

shell 是一个程序,它是提供用户和内核之间交互的接口。

内核是 Linux 操作系统的核心,它管理用户和操作系统之间的所有内容。Shell 可供所有用户在启动终端时使用。终端启动后,用户可以运行任何可用的命令。当 shell 完成命令的执行时,你将在终端窗口上获取输出。

Bash(全称是 Bourne Again Shell)是运行在今天的大多数 Linux 发行版上的默认的 shell,它非常受欢迎,并具有很多功能。但今天我们将讨论 Fish Shell 。

什么是 Fish Shell?

Fish 是友好的交互式 shell ,是一个功能齐全,智能且对用户友好的 Linux 命令行 shell ,它带有一些在大多数 shell 中都不具备的方便功能。

这些功能包括自动补全建议、Sane Scripting、手册页补全、基于 Web 的配置器和 Glorious VGA Color 。你对它感到好奇并想测试它吗?如果是这样,请按照以下安装步骤继续安装。

如何在 Linux 中安装 Fish Shell ?

它的安装非常简单,除了少数几个发行版外,它在大多数发行版中都没有。但是,可以使用以下 fish 仓库 轻松安装。

对于基于 Arch Linux 的系统, 使用 Pacman 命令 来安装 fish shell。

  1. $ sudo pacman -S fish

对于 Ubuntu 16.04/18.04 系统来说,请使用 APT-GET 命令 或者 APT 命令 安装 fish shell。

  1. $ sudo apt-add-repository ppa:fish-shell/release-3
  2. $ sudo apt-get update
  3. $ sudo apt-get install fish

对于 Fedora 系统来说,请使用 DNF 命令 安装 fish shell。

对于 Fedora 29 系统来说:

  1. $ sudo dnf config-manager --add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/shells:fish:release:3.repo
  2. $ sudo dnf install fish

对于 Fedora 28 系统来说:

  1. $ sudo dnf config-manager --add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_28/shells:fish:release:3.repo
  2. $ sudo dnf install fish

对于 Debian 系统来说,请使用 APT-GET 命令 或者 APT 命令 安装 fish shell。

对于 Debian 9 系统来说:

  1. $ sudo wget -nv https://download.opensuse.org/repositories/shells:fish:release:3/Debian_9.0/Release.key -O Release.key
  2. $ sudo apt-key add - < Release.key
  3. $ sudo echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_9.0/ /' > /etc/apt/sources.list.d/shells:fish:release:3.list
  4. $ sudo apt-get update
  5. $ sudo apt-get install fish

对于 Debian 8 系统来说:

  1. $ sudo wget -nv https://download.opensuse.org/repositories/shells:fish:release:3/Debian_8.0/Release.key -O Release.key
  2. $ sudo apt-key add - < Release.key
  3. $ sudo echo 'deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_8.0/ /' > /etc/apt/sources.list.d/shells:fish:release:3.list
  4. $ sudo apt-get update
  5. $ sudo apt-get install fish

对于 RHEL/CentOS 系统来说,请使用 YUM 命令 安装 fish shell。

对于 RHEL 7 系统来说:

  1. $ sudo yum-config-manager --add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/RHEL_7/shells:fish:release:3.repo
  2. $ sudo yum install fish

对于 RHEL 6 系统来说:

  1. $ sudo yum-config-manager --add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/RedHat_RHEL-6/shells:fish:release:3.repo
  2. $ sudo yum install fish

对于 CentOS 7 系统来说:

  1. $ sudo yum-config-manager --add-repo https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_7/shells:fish:release:2.repo
  2. $ sudo yum install fish

对于 CentOS 6 系统来说:

  1. $ sudo yum-config-manager --add-repo https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_6/shells:fish:release:2.repo
  2. $ sudo yum install fish

对于 openSUSE Leap 系统来说,请使用 Zypper 命令 安装 fish shell。

  1. $ sudo zypper addrepo https://download.opensuse.org/repositories/shells:/fish:/release:/3/openSUSE_Leap_42.3/shells:fish:release:3.repo
  2. $ suod zypper refresh
  3. $ sudo zypper install fish

如何使用 Fish Shell ?

一旦你成功安装了 fish shell 。只需在你的终端上输入 fish ,它将自动从默认的 bash shell 切换到 fish shell 。

  1. $ fish

 

自动补全建议

当你在 fish shell 中键入任何命令时,它会在输入几个字母后以浅灰色自动建议一个命令。 

一旦你得到一个建议然后按下向右光标键(LCTT 译注:原文是左,错的)就能完成它而不是输入完整的命令。 

你可以在键入几个字母后立即按下向上光标键检索该命令以前的历史记录。它类似于 bash shell 的 CTRL+r 选项。

Tab 补全

如果你想查看给定命令是否还有其他可能性,那么在键入几个字母后,只需按一下 Tab 键即可。 

再次按 Tab 键可查看完整列表。 

语法高亮

fish 会进行语法高亮显示,你可以在终端中键入任何命令时看到。无效的命令被着色为 RED color 。 

同样的,有效的命令以不同的颜色显示。此外,当你键入有效的文件路径时,fish 会在其下面加下划线,如果路径无效,则不会显示下划线。

基于 Web 的配置器

fish shell 中有一个很酷的功能,它允许我们通过网络浏览器设置颜色、提示符、功能、变量、历史和键绑定。

在终端上运行以下命令以启动 Web 配置界面。只需按下 Ctrl+c 即可退出。

  1. $ fish_config
  2. Web config started at 'file:///home/daygeek/.cache/fish/web_config-86ZF5P.html'. Hit enter to stop.
  3. qt5ct: using qt5ct plugin
  4. ^C
  5. Shutting down.

 

手册页补全

其他 shell 支持可编程的补全,但只有 fish 可以通过解析已安装的手册页自动生成它们。

要使用该功能,请运行以下命令:

  1. $ fish_update_completions
  2. Parsing man pages and writing completions to /home/daygeek/.local/share/fish/generated_completions/
  3. 3466 / 3466 : zramctl.8.gz

如何将 Fish 设置为默认 shell

如果你想测试 fish shell 一段时间,你可以将 fish shell 设置为默认 shell,而不用每次都切换它。

要这样做,首先使用以下命令获取 Fish Shell 的位置。

  1. $ whereis fish
  2. fish: /usr/bin/fish /etc/fish /usr/share/fish /usr/share/man/man1/fish.1.gz

通过运行以下命令将默认 shell 更改为 fish shell 。

  1. $ chsh -s /usr/bin/fish

 

提示:只需验证 Fish Shell 是否已添加到 /etc/shells 目录中。如果不是,则运行以下命令以附加它。

  1. $ echo /usr/bin/fish | sudo tee -a /etc/shells

完成测试后,如果要返回 bash shell ,请使用以下命令。

暂时返回:

  1. $ bash

***返回:

  1. $ chsh -s /bin/bash
责任编辑:庞桂玉 来源: Linux中国
相关推荐

2017-12-11 10:00:00

LinuxshellFish

2023-03-14 16:44:20

Linuxhtop

2018-08-27 14:50:46

LinuxShellBash

2023-07-27 17:41:02

BashZshFish

2022-11-01 15:38:22

LinuxShell

2022-09-19 08:45:52

Telnet系统Linux

2023-07-05 16:45:30

WiresharkLinux

2014-09-26 10:28:39

LinuxPuppet

2021-09-21 15:31:05

Kali LinuxVMware安装

2013-03-06 13:27:03

HadoopLinux

2015-11-30 15:05:01

Linux浏览器Docker

2018-05-30 08:01:17

LinuxNcurses编程库

2023-07-28 09:59:31

2019-02-26 10:00:37

Linux命令内存

2019-10-21 13:28:38

UbuntuPostgreSQL命令

2021-03-14 09:28:24

Linux Shell脚本

2022-10-09 10:18:44

LinuxShell脚本

2022-10-31 08:24:24

UbuntuLinux

2016-12-16 09:23:29

LinuxShell脚本

2020-11-22 07:20:15

LinuxEtcherUSB
点赞
收藏

51CTO技术栈公众号