本文主要介绍如何通过简单步骤提升windows terminal中wsl的linux终端的美观度,以ubuntu为例,其他linux发行版请根据本文流程调整相应命令。假定您已按照我之前的文章安装了windows terminal预编译版本,并成功设置了ubuntu和wsl权限,接下来可以按照本文的指南进行操作。

修改默认源,为apt-get安装提速
由于Ubuntu官方的源速度较慢,建议使用阿里云镜像源来加速apt-get的安装过程。具体操作步骤如下:
首先,备份原配置文件:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.20190516
然后,使用vim打开
sources.list
sudo vim /etc/apt/sources.list
在插入模式下,在文件末尾输入以下命令进行替换:
:%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
输入以下命令安装zsh:
sudo apt-get install zsh

安装Powerline-font中的特定字体
从GitHub仓库下载字体"DejaVu Sans Mono for Powerline"并进行安装。官方GitHub地址为:
https://www.php.cn/link/d56af33e24d2a02c40a53b26fde2bc4a
推荐从我的存储库下载仅需的字体:
https://www.php.cn/link/b29d8617d91303db3e1e5fb653ca0a89
安装字体时,选择对应的ttf文件进行安装,并手动安装"Fira code"或"DejaVu Sans Mono for Powerline"字体。然后在
profiles.json


安装powerline-shell
输入以下命令安装powerline-shell:
cd ~ mkdir src cd src git clone https://www.php.cn/link/efaf6bf0f5a9fc501c049e2fc85f8be4 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://www.php.cn/link/84cceab50d4e4208c84aa83480ebdcf2

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.php.cn/link/3ec7b0f8bc5bf7eb2a73ea78a115d94a
b-ryan/powerline-shell: A beautiful and useful prompt for your shell
https://www.php.cn/link/efaf6bf0f5a9fc501c049e2fc85f8be4
How to Install Powerline Fonts, Symbols for Bash on Windows 10 - The Customize Windows
https://www.php.cn/link/67da624214ee8e89992ce70459e669a3
以上就是黑科技抢先尝(续) - Windows terminal中WSL Linux 终端的极简美化指南的详细内容,更多请关注php中文网其它相关文章!
                        
                        每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
                
                                
                                
                                
                                
                                
                                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号