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

每個 Linux 管理員都可能聽到過 shell 這個詞。你知道什麼是 shell 嗎? 你知道 shell 在 Linux 中的作用是什麼嗎? Linux 中有多少個 shell 可用?

-- Magesh Maruthamuthu

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

$ sudo pacman -S fish

對於 Ubuntu 16.04/18.04 系統來說,請使用 APT-GET 命令 或者 APT 命令 安裝 fish shell。

$ sudo apt-add-repository ppa:fish-shell/release-3

$ sudo apt-get update

$ sudo apt-get install fish

對於 Fedora 系統來說,請使用 DNF 命令 安裝 fish shell。

對於 Fedora 29 系統來說:

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

$ sudo dnf install fish

對於 Fedora 28 系統來說:

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

$ sudo dnf install fish

對於 Debian 系統來說,請使用 APT-GET 命令 或者 APT 命令 安裝 fish shell。

對於 Debian 9 系統來說:

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

$ sudo apt-key add - < Release.key

$ 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

$ sudo apt-get update

$ sudo apt-get install fish

對於 Debian 8 系統來說:

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

$ sudo apt-key add - < Release.key

$ 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

$ sudo apt-get update

$ sudo apt-get install fish

對於 RHEL/CentOS 系統來說,請使用 YUM 命令 安裝 fish shell。

對於 RHEL 7 系統來說:

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

$ sudo yum install fish

對於 RHEL 6 系統來說:

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

$ sudo yum install fish

對於 CentOS 7 系統來說:

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

$ sudo yum install fish

對於 CentOS 6 系統來說:

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

$ sudo yum install fish

對於 openSUSE Leap 系統來說,請使用 Zypper 命令 安裝 fish shell。

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

$ suod zypper refresh

$ sudo zypper install fish

如何使用 Fish Shell ?

一旦你成功安裝了 fish shell 。只需在你的終端上輸入 fish ,它將自動從默認的 bash shell 切換到 fish shell 。

$ fish


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


自動補全建議

當你在 fish shell 中鍵入任何命令時,它會在輸入幾個字母后以淺灰色自動建議一個命令。


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


一旦你得到一個建議然後按下向右光標鍵(LCTT 譯註:原文是左,錯的)就能完成它而不是輸入完整的命令。


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


你可以在鍵入幾個字母后立即按下向上光標鍵檢索該命令以前的歷史記錄。它類似於 bash shell 的 CTRL+r 選項。

Tab 補全

如果你想查看給定命令是否還有其他可能性,那麼在鍵入幾個字母后,只需按一下 Tab 鍵即可。


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


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


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


語法高亮

fish 會進行語法高亮顯示,你可以在終端中鍵入任何命令時看到。無效的命令被着色爲 RED color 。


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


同樣的,有效的命令以不同的顏色顯示。此外,當你鍵入有效的文件路徑時,fish 會在其下面加下劃線,如果路徑無效,則不會顯示下劃線。


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


基於 Web 的配置器

fish shell 中有一個很酷的功能,它允許我們通過網絡瀏覽器設置顏色、提示符、功能、變量、歷史和鍵綁定。

在終端上運行以下命令以啓動 Web 配置界面。只需按下 Ctrl+c 即可退出。

$ fish_config

Web config started at 'file:///home/daygeek/.cache/fish/web_config-86ZF5P.html'. Hit enter to stop.

qt5ct: using qt5ct plugin

^C

Shutting down.


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


手冊頁補全

其他 shell 支持可編程的補全,但只有 fish 可以通過解析已安裝的手冊頁自動生成它們。

要使用該功能,請運行以下命令:

$ fish_update_completions

Parsing man pages and writing completions to /home/daygeek/.local/share/fish/generated_completions/

3466 / 3466 : zramctl.8.gz

如何將 Fish 設置爲默認 shell

如果你想測試 fish shell 一段時間,你可以將 fish shell 設置爲默認 shell,而不用每次都切換它。

要這樣做,首先使用以下命令獲取 Fish Shell 的位置。

$ whereis fish

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

通過運行以下命令將默認 shell 更改爲 fish shell 。

$ chsh -s /usr/bin/fish


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


提示:只需驗證 Fish Shell 是否已添加到 /etc/shells 目錄中。如果不是,則運行以下命令以附加它。

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

完成測試後,如果要返回 bash shell ,請使用以下命令。

暫時返回:

$ bash

永久返回:

$ chsh -s /bin/bash


via: https://www.2daygeek.com/linux-fish-shell-friendly-interactive-shell/

作者: Magesh Maruthamuthu 選題: lujun9972 譯者: zero-MK 校對: wxy

本文由 LCTT 原創編譯, Linux中國 榮譽推出

點擊“瞭解更多”可訪問文內鏈接

相關文章