如何在Linux中安裝、配置和使用Fish Shell?
每個 Linux 管理員都可能聽到過 shell 這個詞。你知道什么是 shell 嗎? 你知道 shell 在 Linux 中的作用是什么嗎? Linux 中有多少個 shell 可用?
shell 是一個程序,它是提供用戶和內(nèi)核之間交互的接口。
內(nèi)核是 Linux 操作系統(tǒng)的核心,它管理用戶和操作系統(tǒng)之間的所有內(nèi)容。Shell 可供所有用戶在啟動終端時使用。終端啟動后,用戶可以運(yùn)行任何可用的命令。當(dāng) shell 完成命令的執(zhí)行時,你將在終端窗口上獲取輸出。
Bash(全稱是 Bourne Again Shell)是運(yùn)行在今天的大多數(shù) Linux 發(fā)行版上的默認(rèn)的 shell,它非常受歡迎,并具有很多功能。但今天我們將討論 Fish Shell 。
什么是 Fish Shell?
Fish 是友好的交互式 shell ,是一個功能齊全,智能且對用戶友好的 Linux 命令行 shell ,它帶有一些在大多數(shù) shell 中都不具備的方便功能。
這些功能包括自動補(bǔ)全建議、Sane Scripting、手冊頁補(bǔ)全、基于 Web 的配置器和 Glorious VGA Color 。你對它感到好奇并想測試它嗎?如果是這樣,請按照以下安裝步驟繼續(xù)安裝。
如何在 Linux 中安裝 Fish Shell ?
它的安裝非常簡單,除了少數(shù)幾個發(fā)行版外,它在大多數(shù)發(fā)行版中都沒有。但是,可以使用以下 fish 倉庫 輕松安裝。
對于基于 Arch Linux 的系統(tǒng), 使用 Pacman 命令 來安裝 fish shell。
$ sudo pacman -S fish
對于 Ubuntu 16.04/18.04 系統(tǒng)來說,請使用 APT-GET 命令 或者 APT 命令 安裝 fish shell。
$ sudo apt-add-repository ppa:fish-shell/release-3
$ sudo apt-get update
$ sudo apt-get install fish
對于 Fedora 系統(tǒng)來說,請使用 DNF 命令 安裝 fish shell。
對于 Fedora 29 系統(tǒng)來說:
$ 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 系統(tǒng)來說:
$ 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 系統(tǒng)來說,請使用 APT-GET 命令 或者 APT 命令 安裝 fish shell。
對于 Debian 9 系統(tǒng)來說:
$ 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 系統(tǒng)來說:
$ 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 系統(tǒng)來說,請使用 YUM 命令 安裝 fish shell。
對于 RHEL 7 系統(tǒng)來說:
$ 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 系統(tǒng)來說:
$ 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 系統(tǒng)來說:
$ 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 系統(tǒng)來說:
$ 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 系統(tǒng)來說,請使用 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
,它將自動從默認(rèn)的 bash shell 切換到 fish shell 。
$ fish
自動補(bǔ)全建議
當(dāng)你在 fish shell 中鍵入任何命令時,它會在輸入幾個字母后以淺灰色自動建議一個命令。
一旦你得到一個建議然后按下向右光標(biāo)鍵(LCTT 譯注:原文是左,錯的)就能完成它而不是輸入完整的命令。
你可以在鍵入幾個字母后立即按下向上光標(biāo)鍵檢索該命令以前的歷史記錄。它類似于 bash shell 的 CTRL+r
選項(xiàng)。
Tab 補(bǔ)全
如果你想查看給定命令是否還有其他可能性,那么在鍵入幾個字母后,只需按一下 Tab
鍵即可。
再次按 Tab
鍵可查看完整列表。
語法高亮
fish 會進(jìn)行語法高亮顯示,你可以在終端中鍵入任何命令時看到。無效的命令被著色為 RED color
。
同樣的,有效的命令以不同的顏色顯示。此外,當(dāng)你鍵入有效的文件路徑時,fish 會在其下面加下劃線,如果路徑無效,則不會顯示下劃線。
基于 Web 的配置器
fish shell 中有一個很酷的功能,它允許我們通過網(wǎng)絡(luò)瀏覽器設(shè)置顏色、提示符、功能、變量、歷史和鍵綁定。
在終端上運(yùn)行以下命令以啟動 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.
手冊頁補(bǔ)全
其他 shell 支持可編程的補(bǔ)全,但只有 fish 可以通過解析已安裝的手冊頁自動生成它們。
要使用該功能,請運(yùn)行以下命令:
$ fish_update_completions
Parsing man pages and writing completions to /home/daygeek/.local/share/fish/generated_completions/
3466 / 3466 : zramctl.8.gz
如何將 Fish 設(shè)置為默認(rèn) shell
如果你想測試 fish shell 一段時間,你可以將 fish shell 設(shè)置為默認(rèn) shell,而不用每次都切換它。
要這樣做,首先使用以下命令獲取 Fish Shell 的位置。
$ whereis fish
fish: /usr/bin/fish /etc/fish /usr/share/fish /usr/share/man/man1/fish.1.gz
通過運(yùn)行以下命令將默認(rèn) shell 更改為 fish shell 。
$ chsh -s /usr/bin/fish
提示:只需驗(yàn)證 Fish Shell 是否已添加到 /etc/shells
目錄中。如果不是,則運(yùn)行以下命令以附加它。
$ echo /usr/bin/fish | sudo tee -a /etc/shells
完成測試后,如果要返回 bash shell ,請使用以下命令。
暫時返回:
$ bash
***返回:
$ chsh -s /bin/bash