免除切换系统之麻烦(瞎说)
准备
- Windows 10 (建议最新版本,旧版本可能不支持Wsl,我的是20H2,最好搞专业版)
- Arch Linux Wsl
- Windows Terminal
- XLaunch
Windows配置
启用“适用于Linux的Windows子系统”和“虚拟机平台”,如下图
然后重启电脑
Arch Wsl配置
安装
从Github下载ArchWsl
然后将ArchWsl放到可读写目录,不然安装完成必报错
然后打开ArchWsl的Arch.exe文件
配置源
编辑/etc/pacman.d/mirrorlist添加China源(例如阿里云)
Server = http://mirrors.aliyun.com/archlinux/$repo/os/$arch`
然后运行
pacman-key --init
pacman-key --populate
pacman -Syyu
启+用multilib库,使用nano编辑/etc/pacman.conf取消下面两行注释
...
[multilib]
Include = /etc/pacman.d/mirrorlist
...
取消注释Color,启用彩色输出(可忽略)
...
color
...
添加archlinuxcn源到/etc/pacman.conf末尾
...
[archlinuxcn]
Server = https://mirrors.aliyun.com/archlinuxcn/$arch
然后运行以下命令
pacman -Syyu
pacman -S archlinuxcn-keyring
更改为Wsl2
最后关闭窗口,打开PowerShell,将Arch转换为Wsl2(需要一定时间)
wsl --set-version Arch 2
安装和配置软件
安装必备软件
pacman -S yay gcc clang lib32-gcc-libs gdb make binutils git openssh man-pages ccls neofetch lolcat bat tokei tree screenfetch wget curl git
使用yay
使用yay需要普通用户权限,所以我们需要创建普通用户
# 创建
useradd -m -G wheel yourname
# 设置密码
passwd yourname
# 在/etc/sudoers将wheel注释去掉
...
%wheel ALL=(ALL) ALL
...
# 切换普通用户
su yourname
zsh安装与配置
使用pacman安装zsh
pacman -S zsh
将zsh设置默认shell
chsh -s /bin/zsh
安装oh-my-sh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # 配置主题(推荐powerlevel10k)
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
# 编辑 ~/.zshrc
ZSH_THEME="powerlevel10k/powerlevel10k".
# 末尾添加
POWERLEVEL9K_MODE="awesome-patched"
Windows Terminal
安装字体,我使用的是MesloLGS NF
配置表如下
// This file was initially generated by Windows Terminal 1.3.2651.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{a5a97cb8-8961-5535-816d-772efe0c6a3f}",
// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings
// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,
// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,
// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
"acrylicOpacity": 0.8, //背景透明度
// "useAcrylic": true, // 启用毛玻璃
"backgroundImage": "C:\\Users\\reall\\Pictures\\85028144_p0.png", //背景图片(可省略)
"backgroundImageOpacity": 0.5, //图片透明度
"backgroundImageStretchMode": "uniformToFill", //填充模式
"icon": "C:\\Users\\reall\\Documents\\Arch\\4.png", //图标
"fontFace": "MesloLGS NF", //字体
"fontSize": 14, //文字大小
//"colorScheme": "Solarized Light", //主题
"cursorColor": "#FFFFFF", //光标颜色
"cursorShape": "bar" //光标形状
},
"list":
[
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "命令提示符",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"source": "Windows.Terminal.PowershellCore"
},
{
"guid": "{a5a97cb8-8961-5535-816d-772efe0c6a3f}",
"hidden": false,
"name": "Arch",
"source": "Windows.Terminal.Wsl"
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
}
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [],
// Add custom actions and keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
"actions":
[
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },
// Press Ctrl+Shift+F to open the search box
{ "command": "find", "keys": "ctrl+shift+f" },
// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
]
}
终端效果
XLaunch
安装后像下图配置
配置 WSL 参数
echo 'export DISPLAY=:0.0' >> .profile
最终效果
参考
https://juejin.im/post/6844904064535248909
https://blog.csdn.net/kk3909/article/details/105120234
https://www.linuxidc.com/Linux/2020-04/162879.htm