在Fedora上優(yōu)化bash或zsh
本文將向你展示如何在 Fedora 的命令行解釋器(CLI)Shell 中設(shè)置一些強大的工具。如果使用bash(默認)或zsh,F(xiàn)edora 可讓你輕松設(shè)置這些工具。
前置需求
這需要一些已安裝的軟件包。在 Fedora 工作站上,運行以下命令:
sudo dnf install git wget curl ruby ruby-devel zsh util-linux-user redhat-rpm-config gcc gcc-c++ make
在 Silverblue 上運行:
sudo rpm-ostree install git wget curl ruby ruby-devel zsh util-linux-user redhat-rpm-config gcc gcc-c++ make
注意:在 Silverblue 上,你需要重新啟動才能繼續(xù)。
字體
你可以通過安裝新字體使終端煥然一新。為什么不使用可以同時顯示字符和圖標(biāo)的字體呢?
Nerd-Fonts
打開一個新終端,然后鍵入以下命令:
git clone https://github.com/ryanoasis/nerd-fonts ~/.nerd-fonts
cd .nerd-fonts
sudo ./install.sh
Awesome-Fonts
在工作站上,使用以下命令進行安裝:
sudo dnf fontawesome-fonts
在 Silverblue 上鍵入:
sudo rpm-ostree install fontawesome-fonts
Powerline
Powerline 是 vim 的狀態(tài)行插件,并為其他幾個應(yīng)用程序也提供了狀態(tài)行和提示符,包括 bash、zsh、tmus、i3、Awesome、IPython 和 Qtile。你也可以在官方文檔站點上找到更多信息。
安裝
要在 Fedora 工作站上安裝 Powerline 實用程序,請打開一個新終端并運行:
sudo dnf install powerline vim-powerline tmux-powerline powerline-fonts
在 Silverblue 上,命令更改為:
sudo rpm-ostree install powerline vim-powerline tmux-powerline powerline-fonts
注意:在 Silverblue 上,你需要重新啟動才能繼續(xù)。
激活 Powerline
要使 Powerline 默認處于活動狀態(tài),請將下面的代碼放在 ~/.bashrc
文件的末尾:
if [ -f `which powerline-daemon` ]; then
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /usr/share/powerline/bash/powerline.sh
fi
最后,關(guān)閉終端并打開一個新終端。它看起來像這樣:
Oh-My-Zsh
Oh-My-Zsh 是用于管理 Zsh 配置的框架。它捆綁了有用的功能、插件和主題。要了解如何將 Zsh 設(shè)置為默認外殼程序,請參見這篇文章。
安裝
在終端中輸入:
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
或者,你也可以輸入以下內(nèi)容:
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
最后,你將看到如下所示的終端:
恭喜,Oh-my-zsh 已安裝成功。
主題
安裝后,你可以選擇主題。我喜歡使用 powerlevel10k。優(yōu)點之一是它比 powerlevel9k 主題快 100 倍。要安裝它,請運行以下命令行:
git clone https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/themes/powerlevel10k
并在你的 ~/.zshrc
文件設(shè)置 ZSH_THEME
:
ZSH_THEME=powerlevel10k/powerlevel10k
關(guān)閉終端。再次打開終端時,powerlevel10k 配置向?qū)⒃儐柲銕讉€問題以正確配置提示符。
完成 powerline10k 配置向?qū)Ш?,你的提示符將如下所示?/p>
如果你不喜歡它。你可以隨時使用 p10k configure
命令來運行 powerline10k 向?qū)А?/p>
啟用插件
插件存儲在 .oh-my-zsh/plugins
文件夾中。要激活插件,你需要編輯 ~/.zshrc
文件。安裝插件意味著你創(chuàng)建了一系列執(zhí)行特定功能的別名或快捷方式。
例如,要啟用 firewalld 和 git 插件,請首先編輯 ~/.zshrc
:
plugins=(firewalld git)
注意:使用空格分隔插件名稱列表。
然后重新加載配置:
source ~/.zshrc
要查看創(chuàng)建的別名,請使用以下命令:
alias | grep firewall
更多配置
我建議安裝語法高亮和語法自動建議插件。
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
將它們添加到文件 ~/.zshrc
的插件列表中。
plugins=( [plugins...] zsh-syntax-highlighting zsh-autosuggestions)
重新加載配置。
source ~/.zshrc
查看結(jié)果:
彩色的文件夾和圖標(biāo)
colorls
是一個 ruby gem,可使用顏色和超棒的字體圖標(biāo)美化終端的 ls
命令。你可以訪問官方網(wǎng)站以獲取更多信息。
因為它是個 ruby gem,所以請按照以下簡單步驟操作:
sudo gem install colorls
要保持最新狀態(tài),只需執(zhí)行以下操作:
sudo gem update colorls
為防止每次輸入 colorls
,你可以在 ~/.bashrc
或 ~/.zshrc
中創(chuàng)建別名。
alias ll='colorls -lA --sd --gs --group-directories-first'
alias ls='colorls --group-directories-first'
另外,你可以為 colorls
的選項啟用制表符補完功能,只需在 shell 配置末尾輸入以下行:
source $(dirname ($gem which colorls))/tab_complete.sh
重新加載并查看會發(fā)生什么: