自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在Linux上安裝友好的交互式shell:Fish

系統(tǒng) Linux
Fish,友好的交互式 shell 的縮寫,它是一個適于裝備于類 Unix 系統(tǒng)的智能而用戶友好的 shell。Fish 有著很多重要的功能,比如自動建議、語法高亮、可搜索的歷史記錄、智能搜索功能、極好的 VGA 顏色支持、基于 web 的設置方式、完善的手冊頁和許多開箱即用的功能。在這篇教程中,我們討論如何在 Linux 中安裝和使用 fish shell。

 [[212770]]

Fish,友好的交互式 shell 的縮寫,它是一個適于裝備于類 Unix 系統(tǒng)的智能而用戶友好的 shell。Fish 有著很多重要的功能,比如自動建議、語法高亮、可搜索的歷史記錄(像在 bash 中 CTRL+r)、智能搜索功能、極好的 VGA 顏色支持、基于 web 的設置方式、完善的手冊頁和許多開箱即用的功能。盡管安裝并立即使用它吧。無需更多其他配置,你也不需要安裝任何額外的附加組件/插件!

在這篇教程中,我們討論如何在 Linux 中安裝和使用 fish shell。

安裝 Fish

盡管 fish 是一個非常用戶友好的并且功能豐富的 shell,但并沒有包括在大多數 Linux 發(fā)行版的默認倉庫中。它只能在少數 Linux 發(fā)行版中的官方倉庫中找到,如 Arch Linux,Gentoo,NixOS,和 Ubuntu 等。然而,安裝 fish 并不難。

在 Arch Linux 和它的衍生版上,運行以下命令來安裝它。

  1. sudo pacman -S fish 

在 CentOS 7 上以 root 運行以下命令:   

  1. cd /etc/yum.repos.d/ 
  2.  
  3. wget https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_7/shells:fish:release:2.repo 
  4.  
  5. yum install fish 

在 CentOS 6 上以 root 運行以下命令:

  1. cd /etc/yum.repos.d/ 
  2.  
  3. wget https://download.opensuse.org/repositories/shells:fish:release:2/CentOS_6/shells:fish:release:2.repo 
  4.  
  5. yum install fish 

在 Debian 9 上以 root 運行以下命令:   

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

在 Debian 8 上以 root 運行以下命令:

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

在 Fedora 26 上以 root 運行以下命令:

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

在 Fedora 25 上以 root 運行以下命令:

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

在 Fedora 24 上以 root 運行以下命令:

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

在 Fedora 23 上以 root 運行以下命令:

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

在 openSUSE 上以 root 運行以下命令:

  1. zypper install fish 

在 RHEL 7 上以 root 運行以下命令:

  1. cd /etc/yum.repos.d/ 
  2.  
  3. wget https://download.opensuse.org/repositories/shells:fish:release:2/RHEL_7/shells:fish:release:2.repo 
  4.  
  5. yum install fish 

在 RHEL-6 上以 root 運行以下命令:

  1. cd /etc/yum.repos.d/ 
  2.  
  3. wget https://download.opensuse.org/repositories/shells:fish:release:2/RedHat_RHEL-6/shells:fish:release:2.repo 
  4.  
  5. yum install fish 

在 Ubuntu 和它的衍生版上:

  1. sudo apt-get update 
  2.  
  3. sudo apt-get install fish 

就這樣了。是時候探索 fish shell 了。

用法

要從你默認的 shell 切換到 fish,請執(zhí)行以下操作:

  1. $ fish 
  2.  
  3. Welcome to fish, the friendly interactive shell 

你可以在 ~/.config/fish/config.fish 上找到默認的 fish 配置(類似于 .bashrc)。如果它不存在,就創(chuàng)建它吧。

自動建議

當我輸入一個命令,它以淺灰色自動建議一個命令。所以,我需要輸入一個 Linux 命令的前幾個字母,然后按下 tab 鍵來完成這個命令。

如果有更多的可能性,它將會列出它們。你可以使用上/下箭頭鍵從列表中選擇列出的命令。在選擇你想運行的命令后,只需按下右箭頭鍵,然后按下 ENTER 運行它。

無需 CTRL+r 了!正如你已知道的,我們通過按 CTRL+r 來反向搜索 Bash shell 中的歷史命令。但在 fish shell 中是沒有必要的。由于它有自動建議功能,只需輸入命令的前幾個字母,然后從歷史記錄中選擇已經執(zhí)行的命令。很酷,是吧。

智能搜索

我們也可以使用智能搜索來查找一個特定的命令、文件或者目錄。例如,我輸入一個命令的一部分,然后按向下箭頭鍵進行智能搜索,再次輸入一個字母來從列表中選擇所需的命令。

語法高亮

當你輸入一個命令時,你將注意到語法高亮。請看下面當我在 Bash shell 和 fish shell 中輸入相同的命令時截圖的區(qū)別。

Bash:

Fish:

正如你所看到的,sudo 在 fish shell 中已經被高亮顯示。此外,默認情況下它將以紅色顯示無效命令。

基于 web 的配置方式

這是 fish shell 另一個很酷的功能。我們可以設置我們的顏色、更改 fish 提示符,并從網頁上查看所有功能、變量、歷史記錄、鍵綁定。

啟動 web 配置接口,只需輸入:

  1. fish_config 

手冊頁補完

Bash 和 其它 shells 支持可編程的補完,但只有 fish 可以通過解析已安裝的手冊來自動生成它們。

為此,請運行:

  1. fish_update_completions 

實例輸出將是:

  1. Parsing man pages and writing completions to /home/sk/.local/share/fish/generated_completions/ 
  2.  
  3.  3435 / 3435 : zramctl.8.gz 

禁用問候語

默認情況下,fish 在啟動時問候你(“Welcome to fish, the friendly interactive shell”)。如果你不想要這個問候消息,可以禁用它。為此,編輯 fish 配置文件:

  1. vi ~/.config/fish/config.fish 

添加以下行:

  1. set -g -x fish_greeting '' 

你也可以設置任意自定義的問候語,而不是禁用 fish 問候。

  1. set -g -x fish_greeting 'Welcome to OSTechNix' 

獲得幫助

這是另一個吸引我的令人印象深刻的功能。要在終端的默認 web 瀏覽器中打開 fish 文檔頁面,只需輸入:

  1. help 

官方文檔將會在你的默認瀏覽器中打開。另外,你可以使用手冊頁來顯示任何命令的幫助部分。

  1. man fish 

設置 fish 為默認 shell

非常喜歡它?太好了!設置它作為默認 shell 吧。為此,請使用命令 chsh:

 

  1. chsh -s /usr/bin/fish 

在這里,/usr/bin/fish 是 fish shell 的路徑。如果你不知道正確的路徑,以下命令將會幫助你:

  1. which fish 

注銷并且重新登錄以使用新的默認 shell。

請記住,為 Bash 編寫的許多 shell 腳本可能不完全兼容 fish。

要切換回 Bash,只需運行:

 

  1. bash 

如果你想 Bash 作為你的永久默認 shell,運行:

  1. chsh -s /bin/bash 

各位,這就是全部了。在這個階段,你可能會得到一個有關 fish shell 使用的基本概念。 如果你正在尋找一個Bash的替代品,fish 可能是一個不錯的選擇。

責任編輯:龐桂玉 來源: Linux中國
相關推薦

2020-04-06 20:47:42

FishShellLinux

2019-03-18 13:00:15

LinuxFish ShellBash

2018-05-21 14:44:33

LinuxshellPython

2015-09-09 13:29:17

FISHShellLinux

2020-04-21 14:21:31

LinuxPython

2021-10-12 08:43:19

LinuxSambaWindows

2019-11-26 09:20:47

LinuxJava

2011-11-10 09:19:24

虛擬化云計算VMware

2022-07-14 14:37:05

Linux軟件開發(fā)工具

2021-08-18 11:19:25

FedoraLinuxJava

2021-09-11 15:41:55

UbuntuDropbox云服務

2017-03-29 16:18:11

LinuxUbuntuRedmine

2021-07-12 14:47:16

UbuntuZlib代碼

2021-11-28 06:33:24

Discord消息收發(fā)應用 Linux

2012-05-21 10:31:06

LinuxVMware Tool

2020-12-18 08:00:00

Python開發(fā)Web

2023-07-27 17:41:02

BashZshFish

2021-03-07 11:46:02

UbuntuLinuxErlang

2025-02-25 10:40:00

圖像生成工具模型

2014-06-23 10:09:20

MacBook ProLinux
點贊
收藏

51CTO技術棧公眾號