一、概述
在学习webpack过程中需要使用终端来实验,网课中看到老师的命令行非常好看,首先是美观,还有一个很关键的就是行内信息含量多,再就是可以通过插件辅助操作命令行,会让效率提高,但是老师所使用的是macOs,其命令行支持使用ohmyzsh,windows并不支持,本文通过使用win10 系统中最新的WSL 子系统的功能,以及windows Terminal来进行命令行的美化,从而完美的实现ohmyzsh中的主题以及插件。
注意:本次教程使用的是Win10 1904 版本以上的windows进行测试(1904以下的版本均没有测试过),建议完全按照教程中的步骤进行以免出错。
二、配置过程
1.安装 Windows terminal
在windows store中,首先安装 Windows terminal
2.开启子系统功能,并安装Ubuntu 20.04
务必!!!在安装之前首先要开启windows中的wsl子系统功能
重启电脑
打开windows store安装Ubuntu 20.04
2.1设置Ubuntu 20.04
2.1.1将ubuntu设置为默认的启动命令行
启动后设置好root的用户名和密码直接关掉Ubuntu的终端就可以
打开windows Terminal 终端 进行设置
在Vscode中编辑setting.json
Ubuntu 的guid
2.1.2 更改Ubuntu的更新源为阿里源
使用的是 windows商店中的Ubuntu 20.04 那么就可以直接使用我的命令进行更改
进入源文件
sudo vim /etc/apt/sources.list
首先使用命令 直接键盘输入<kbd>g</kbd> + <kbd>g</kbd> + <kbd>Shift</kbd> + <kbd>v</kbd>+<kbd>Shift</kbd>+<kbd>G</kbd> + <kbd>del</kbd>
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
Ubuntu的设置
设置默认打开终端为Ubuntu18.04
再powershell 中输入
wslconfig /l
设置默认为你想要的系统号:
wslconfig /setdefault Ubuntu-20.04
wslconfig /setdefault Ubuntu-18.04
在终端中:设置 source.list源
首先要看版本号
lsb_release -a
确认无误后更改源
直接用这份:
sudo vim /etc/apt/sources.list
i 插入 :wq 保存退出
Ubuntu 18.04
Codename 为bionic的源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
Ubuntu 20.04
Codename 为focal的源
deb-src http://archive.ubuntu.com/ubuntu focal main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu focal partner
deb-src http://archive.canonical.com/ubuntu focal partner
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
测试好用
执行更新
sudo apt update
设置中文环境(可选)
1. 安装中文语言包
sudo apt install -y language-pack-zh-hans language-pack-zh-hans-base
2. 导入中文环境
export LC_ALL=zh_CN.UTF-8
3. 修改 locale
sudo vim /etc/default/locale
LANG=zh_CN.UTF-8
LANGUAGE="zh_CN:zh"
安装zsh
sudo apt install zsh
确认版本号 zsh --version(确认安装成功)
安装curl
sudo apt install curl
安装ohmyzsh
1.官方推荐(本人不推荐curl基本被墙,不想走代理直接看2)
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
如果你尝试 curl 不好用报错35(其他报错直接跳2看完美解决方案) 可以尝试使用 让你的子系统使用代理
其中ubuntu的方法为proxychains这个方法
1.1安装proxychains 并设置proxychains 的端口为你的socks5端口
sudo apt install proxychains
设置最后一行为你的socks5 端口
sudo vim /etc/proxychains.conf
socks5 127.0.0.1 1081
当然你也可以直接按照我这个步骤操作
proxychains git clone https://github.com/ohmyzsh/ohmyzsh.git
ls
cd ohmyzsh
cd tools
sh install.sh
尝试可以成功(已测试)
2.官方推荐方法基本不好用,建议直接使用gitee 镜像 ohmyzsh (踩坑15小时的经验)
git clone https://gitee.com/mirrors/oh-my-zsh.git
下载完后进入tools目录进行安装
我的操作是:先进入目录,然后sh安装
ls
cd ohmyzsh
cd tools
sh install.sh
install.sh 过程没法走代理,目前没研究明白,慢慢等待吧。东西不大
这样就是成功了第一步!
选择设置wsl的终端,并在vscode中默认设置好。
这时候你看到的样式完全不像别人那种酷酷的什么都有。像这样
有这些图标是不可能的win10下必须要安装必须的字体才能实现这种效果。
因此我们设置ohmyzsh 主题和插件以及字体(10/20)