【WSL2】 zsh-syntax-highlighting Very low speed on WSL2

本文介绍了如何通过修改/etc/wsl.conf文件来阻止Windows路径自动添加到WSL的PATH中,以避免混淆不同版本的程序。步骤包括设置appendWindowsPath为false,重启WSL,然后手动添加你需要的Windows执行文件,如VSCode。文章提供了创建别名或脚本来调用Windows程序的方法,并强调了这种方法可以保持WSL环境的整洁。

@BigTear

In /etc/wsl.conf (create if it doesn't exist) add:

[interop]
appendWindowsPath=false

Afterwards run wsl --shutdown and open a new session for the changes to take effect. Note that this will mean Windows executables are no longer in your PATH, e.g., commands like code will no longer work. I think this is better anyway bc it unclutters your WSL PATH and could prevent any problems arising from using the Windows version of something accidentally when you meant to use the Linux version. However, you will manually need to re-add all the Windows executables you care about, like code either:

by creating an alias for the executable

alias code="/mnt/c/[your vscode installation directory]/bin/code"

or by creating a new script that redirects code to the executable

#!/usr/bin/env bash

/mnt/c/[your vscode installation directory]/bin/code "$@"

Also if you do that latter, remember you need to run chmod +x on it and make it available in your PATH for it to be executable from anywhere.

e.g.

# assuming "$HOME/.local/bin" exists and is on your PATH...
echo -e '#!/usr/bin/env bash\n/mnt/c/[your vscode installation directory]/bin/code "$@"' > "$HOME/.local/bin/code"
chmod +x "$HOME/.local/bin/code"

You could also just re-add the executable directory to your PATH variable, but I think that defeats the purpose of cleaning /mnt/* entries from your PATH.

<think>好的,我需要帮助用户在WSL2中安装和配置Zsh Shell。首先,我得回顾用户提供的引用资料,看看里面有哪些有用的步骤。 根据引用[1]和[2],安装Zsh需要先通过sudo apt install zsh命令。然后安装oh-my-zsh,可以使用curl或wget的方法,比如引用[3]中的命令:sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"。安装完成后,可能需要将默认shell改为Zsh,使用chsh -s $(which zsh)。 接下来是配置部分,引用[4]提到可以在~/.zshrc中添加插件,比如zsh-completions,还有安装fzf进行模糊搜索。用户可能还需要安装一些主题或插件,比如Powerlevel10k,这需要额外步骤,比如克隆仓库和修改.zshrc文件。 需要注意的是,用户使用的是WSL2,可能需要处理一些权限问题,或者在安装过程中遇到依赖项缺失的情况,比如确保已安装git和curl。此外,安装oh-my-zsh时可能会失败,可能需要检查网络连接或者手动下载安装脚本。 最后,生成相关问题时要考虑用户可能遇到的后续步骤,比如配置主题、优化性能或解决常见错误。需要确保问题覆盖安装、配置、优化和故障排除等方面。</think>### 在 WSL2 中安装和配置 Zsh Shell 的步骤 #### 1. **安装 Zsh** - 更新软件包列表并安装 `zsh`: ```bash sudo apt update && sudo apt install zsh -y ``` - 验证安装是否成功: ```bash which zsh # 输出应为 /usr/bin/zsh [^1] ``` #### 2. **安装 oh-my-zsh** - 使用官方脚本安装(任选一种方式): ```bash # 使用 curl sh -c "$(curl -fsSL https://install.ohmyz.sh/)" # 或使用 wget sh -c "$(wget -O- https://install.ohmyz.sh/)" ``` 安装完成后,终端会自动切换到 Zsh[^2][^3]。 #### 3. **设置 Zsh 为默认 Shell** - 如果未自动设置,手动修改默认 Shell: ```bash chsh -s $(which zsh) ``` - 重启终端或执行 `zsh` 进入新 Shell。 #### 4. **基础配置** - **主题与插件** 编辑 `~/.zshrc` 文件: ```bash ZSH_THEME="robbyrussell" # 默认主题,可替换为其他主题如 "agnoster" plugins=(git zsh-autosuggestions zsh-syntax-highlighting) ``` - 应用配置: ```bash source ~/.zshrc ``` #### 5. **高级配置(可选)** - **安装 `fzf` 模糊搜索工具** 克隆仓库并运行安装脚本: ```bash git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf ~/.fzf/install # 按提示选择配置 ``` - **启用自动补全插件** 在 `~/.zshrc` 的 `plugins` 数组中添加 `zsh-completions`[^4]。 --- ### 常见问题解决 - **安装 oh-my-zsh 失败** 检查网络连接,或尝试通过代理执行脚本。 - **主题显示异常** 安装 Powerline 字体: ```bash sudo apt install fonts-powerline ``` ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值