入坑wsl

用了一个月的mac os, 又回归windows了, mac确实好看, 终端配合iterm2也很舒服, 奈何终究我们不合适...生态毕竟没有windows那么丰富;

切回windows最无法忍受的就是windows的终端了, 不管是cmd.exe还是包裹了windows terminalpowershell.exe, 用起来都不是那么的顺手, 好在微软早就推出了wsl(windows subsystem for linux), 是时候"入坑"了;

"入坑"wsl后的第一个问题 ---- 内存占用过高

我在安装docker desktop for windows时, 它提示我可以使用基于wsl2的引擎来提高docker在windows上的性能, 所以我就勾选了, 并按照它的提示进行操作, 装好后跑了几个容器发现内存跑到95%左右...这样肯定是不行的, 动动鼠标都掉帧...

好在不是没有解决方案的, 可以通过修改wsl的配置文件解决; 在$HOME目录下新建或编辑.wslconfig文件, 加入如下的内容(可以根据自己电脑的配置自行调整, 我目前使用的设备是16G+500G的)

[wsl2]
memory=4GB
swap=8GB
localhostForwarding=true

然后保存, 重启wsl

# 需要管理员权限
net stop LxssManager
net start LxssManager

wsl使用zsh, 并配置主题 agnoster

  1. 安装 zsh

sudo apt-get install zsh

  1. 安装 oh-my-zsh

使用在线脚本安装
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

  1. 主题

使用agnoster主题需要先安装字体FiraCode, 下载后的文件中有一个readme文件里面有安装字体的方法

安装好字体后, 还需要配置承载zsh shell的客户端的字体; 就是说比如用的是windows terminal的话, 那么需要修改其字体为Fira Mono for Powerline

image

然后修改.zshrc文件

$HOME && vim .zshrc

修改 ZSH_THEME="agnoster"

这时候发现目录的背景色有点怪怪的, 看不清, 所以还需要调整一下

cp ~/.oh-my-zsh/theme/agnoster.zsh-theme ~/.oh-my-zsh/custom/theme/agnoster_wsl.zsh-theme && vim ~/.oh-my-zsh/custom/theme/agnoster_wsl.zsh-theme

修改下面的部分

# Dir: current working directory
prompt_dir() {
  prompt_segment 075 $CURRENT_FG '%~' # blue修改成了075
}

保存重启wsl, 大功告成

image

配置rider终端使用wsl

image

vscode终端使用wsl

image

image

posted @ 2020-11-16 22:48  Laggage  阅读(570)  评论(0编辑  收藏  举报