黑科技抢先尝(续) - Windows terminal中WSL Linux 终端的极简美化指南
之前,本人寫了兩篇文章 黑科技搶先嘗 | Windows全新終端初體驗(附代碼Build全過程)?和 程會玩 | 無需自行編譯也能玩轉 Windows Terminal,介紹了玩轉Windows terminal的兩種方式。
今天這篇文章,主要介紹如何美化 Windows terminal 中 WSL 的 Linux 終端,依然是以本人最熟悉的Ubuntu為例,其他版本的 Linux 請參考本文的流程換用對應的命令。假定你已按我的上一篇文章已安裝好 Windows terminal預編譯版本,同時安裝好了 Ubuntu,并設置號了?WSL的權限,然后就可以按本文繼續操作了。
修改默認源,為apt-get安裝提速
由于?Ubuntu官方的源實在是太慢了,建議大家緩存阿里云鏡像的 Ubuntu 源,其具體操作步驟如下:
首先將原配置文件備份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.20190516
然后 vim 打開sources.list,
sudo vim /etc/apt/sources.list
i(插入)模式下,在末尾輸入依次輸入每一行進行替換:
:%s/security.ubuntu/mirrors.aliyun/g
:%s/archive.ubuntu/mirrors.aliyun/g
每輸入一行,回車一次,然后就替換好了。
更新源:
sudo apt update; sudo apt upgrade
安裝python 和 python pip
依次輸入如下命令:
sudo apt-get install python3
sudo apt-get install build-essential
sudo apt-get install python-pip
pip install --upgrade pip
安裝 zsh
sudo apt-get install zsh
安裝powerline-font中的特定字體
從`github`倉庫中下載字體"DejaVu Sans Mono for Powerline",并安裝。
這里給出官方github的地址,但需要自己下載后找那個字體
powerline/fonts: Patched fonts for Powerline users.
https://github.com/powerline/fonts
更推薦我存放的地方下載(僅存放了所需要的字體):
https://github.com/yanglr/WindowsDevTools/tree/master/awosomeTerminal/fonts-Ubuntu
安裝字體時,選擇對應的哪一個ttf后綴的安裝即可,然后手動安裝字體"Fira code" 或 "DejaVu Sans Mono for Powerline"
然后在命令行應用之,具體操作是在`profiles.json`中把字體設置成它,即可生效。
安裝powerline-shell
cd ~
mkdir src
cd src
git clone https://github.com/b-ryan/powerline-shell
cd powerline-shell
sudo python setup.py install
修改~目錄下的配置文件 .bashrc 和 .zshrc
首先,插入一點背景知識:
ps1格式簡介:
shell有四種不同的命令提示,稱為PS1,PS2,PS3和PS4。 PS代表Prompt String。Windows/Linux/Ubuntu都用得比較多的是PS1腳本。
"$PS1", "Prompt String 1" 指定命令行界面中的環境變量。
先編輯文件?.zshrc
vim ~/.zshrc
在末尾加入內容:
function powerline_precmd() {
PS1="(powerline-shell --shell zsh ?)"
}
function install_powerline_precmd() {
for s in "${precmd_functions[@]}"; do
if [ "$s" = "powerline_precmd" ]; then
return
fi
done
precmd_functions+=(powerline_precmd)
}
if [ "$TERM" != "linux" ]; then
install_powerline_precmd
fi
編輯完后更新文件?.zshrc
source ~/.zshrc
再編輯文件.bashrc
vim ~/.bashrc
在末尾加入內容:
function _update_ps1() {
PS1="(powerline-shell ?)"
}
if [ "$TERM" != "linux" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
編輯完后更新文件?.bashrc
source ~/.bashrc
然后,我隨便輸入幾個命令:
sudo su
ls
此時Windows terminal中的效果如下:
我直接就使用這個默認主題了。
在命令行提示符中插入Emoji表情
那么,如果要在命令提示符中插入 emoji表情,怎么弄呢?就在下圖相應的地方(對應文件?.bashrc)加~
編輯文件.bashrc
vim ~/.bashrc編輯完后更新文件?.bashrc
source ~/.bashrc此時的 Terminal 為:
更有意思的玩法可以參考:
https://loige.co/random-emoji-in-your-prompt-how-and-why/
zsh主題定制
此外,如果想更深入地定制zsh主題,推薦安裝oh_my_zsh,下面詳細介紹。
安裝 oh_my_zsh
Linux下安裝oh-my-zsh,需要在終端輸入命令:
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
如果 遇到證書類似問題
apt-get install ca-certificates
解決權限問題
如果啟動時會出現zsh-syntax-highlighting權限問題,運行下面的命令即可:
compaudit | xargs chmod g-w,o-w
卸載oh_my_zsh的方法
uninstall_oh_my_zsh
從 Windows 10 的 Bash 中運行 WSL
對于windows 10中?WSL?獨立的默認Bash窗口,只能選擇字體"DejaVu Sans Mono for Powerline",可以在界面上選擇后使用。
開始菜單中搜索 bash 并打開,
右鍵 屬性-> 字體,選字體"DejaVu Sans Mono for Powerline"。
最后的運行結果是:
Scott Hanselman:
請注意我在 prompt 中也使用了Powerline?。 我正在使用Fira Code?,它含有我需要的glyphs,但你當然也可以使用改進過的Powerline字體或使用像Nerd Fonts和它的字體補丁程序那樣的工具制作自己的字體?。 此字體補丁程序通常用于獲取你最喜歡的等寬字體,并為其添加Powerline glyphs。
注意:如果您看到字形有任何奇怪的間距問題,您可以嘗試使用--use-single-width-glyphs來解決它。 通過發布,我認為所有這些小問題都將得到解決。 在我的終端環境下使用Fira Code沒有任何問題,您的環境可能有所不同。
參考:
修改 WSL Ubuntu 18.04 默認源為阿里云鏡像 - Windows - 大象筆記
https://www.sunzhongwei.com/modify-the-wsl-ubuntu-1804-default-source-for-ali-cloud-images
b-ryan/powerline-shell: A beautiful and useful prompt for your shell
https://github.com/b-ryan/powerline-shell
How to Install Powerline Fonts, Symbols for Bash on Windows 10 - The Customize Windows
https://thecustomizewindows.com/2018/01/install-powerline-fonts-symbols-bash-windows-10/
原文地址:
https://www.cnblogs.com/enjoy233/p/awesome_windows_terminal_build_and_trial.html
Tips
更多精彩文章, 歡迎訪問本人博客https://enjoy233.cnblogs.com 或 知乎搜索「Bravo Yeung」.
歡迎轉發到朋友圈, 公眾號轉載請后臺聯系本人申請授權~
回復m可查看本號文章列表噢, 然后可以點擊鏈接閱讀文章~
也可在收到的列表中找到文章相應編號后回后臺回復編號直達.
推薦閱讀
程會玩 | 無需自行編譯也能玩轉 Windows Terminal
黑科技搶先嘗 | Windows全新終端初體驗(附代碼Build全過程)
中英文電子書下載網站大搜羅
開發者見聞 | ASP.NET Core開發者路線圖
點擊"在看"的人,
2019都會變得特別好看?
總結
以上是生活随笔為你收集整理的黑科技抢先尝(续) - Windows terminal中WSL Linux 终端的极简美化指南的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis作者antirez:开源维护者
- 下一篇: C# 8.0 中开启默认接口实现