linux下fish配置终端,如何在Linux中安装、配置和使用Fish Shell?

5e0ea2a390b8cb1166bb1354355c6e6f.png

每个 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。

$sudopacman-S fish

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

$sudoapt-add-repository ppa:fish-shell/release-3

$sudoapt-getupdate

$sudoapt-getinstall fish

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

对于 Fedora 29 系统来说:

$sudodnf config-manager--add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/shells:fish:release:3.repo

$sudodnf install fish

对于 Fedora 28 系统来说:

$sudodnf config-manager--add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_28/shells:fish:release:3.repo

$sudodnf install fish

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

对于 Debian 9 系统来说:

$sudowget-nv https://download.opensuse.org/repositories/shells:fish:release:3/Debian_9.0/Release.key -O Release.key

$sudoapt-key add-

$sudoecho'deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_9.0/ /'>/etc/apt/sources.list.d/shells:fish:release:3.list

$sudoapt-getupdate

$sudoapt-getinstall fish

对于 Debian 8 系统来说:

$sudowget-nv https://download.opensuse.org/repositories/shells:fish:release:3/Debian_8.0/Release.key -O Release.key

$sudoapt-key add-

$sudoecho'deb http://download.opensuse.org/repositories/shells:/fish:/release:/3/Debian_8.0/ /'>/etc/apt/sources.list.d/shells:fish:release:3.list

$sudoapt-getupdate

$sudoapt-getinstall fish

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

对于 RHEL 7 系统来说:

$sudoyum-config-manager--add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/RHEL_7/shells:fish:release:3.repo

$sudoyuminstall fish

对于 RHEL 6 系统来说:

$sudoyum-config-manager--add-repo https://download.opensuse.org/repositories/shells:/fish:/release:/3/RedHat_RHEL-6/shells:fish:release:3.repo

$sudoyuminstall fish

对于 CentOS 7 系统来说:

$sudoyum-config-manager--add-repo https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_7/shells:fish:release:2.repo

$sudoyuminstall fish

对于 CentOS 6 系统来说:

$sudoyum-config-manager--add-repo https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_6/shells:fish:release:2.repo

$sudoyuminstall fish

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

$sudozypper addrepo https://download.opensuse.org/repositories/shells:/fish:/release:/3/openSUSE_Leap_42.3/shells:fish:release:3.repo

$ suod zypper refresh

$sudozypper install fish

如何使用 Fish Shell ?

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

$ fish

4cf1476d21466961118e5ae101c72c32.png

自动补全建议

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

ccdcec600d02885720c61ead6c44d182.png

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

b6f8bc5dd15d4fa1535093d060a4eef5.png

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

Tab 补全

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

afff56f87f65a02788bfc0a2f78e2222.png

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

b3d7ca64bf36fe6dc98962b98096e28a.png

语法高亮

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

d189233d0b72d8248a4f5cb172c131c7.png

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

b6b097a9c42d93406519f03438017fe7.png

基于 Web 的配置器

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

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

$ fish_config

Webconfig started at'file:///home/daygeek/.cache/fish/web_config-86ZF5P.html'.Hitenter to stop.

qt5ct:usingqt5ct plugin

^C

Shuttingdown.

44fa04e25c8bfec7653ffe852db5156a.png

手册页补全

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

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

$ fish_update_completions

Parsingmanpagesandwriting completions to/home/daygeek/.local/share/fish/generated_completions/

3466/3466:zramctl.8.gz

如何将 Fish 设置为默认 shell

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

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

$whereisfish

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

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

$chsh-s/usr/bin/fish

6d0ad50c6f9821b01948f2231b06bc48.png

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

$echo/usr/bin/fish|sudotee-a/etc/shells

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

暂时返回:

$bash

***返回:

$chsh-s/bin/bash

【编辑推荐】

【责任编辑:庞桂玉 TEL:(010)68476606】

点赞 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值