admin管理员组文章数量:1583936
win10 + Terminal + WSL+ oh-my-zsh 配置漂亮实用的windows终端及配置ubuntu不加.exe打开windows程序
未安装wsl/wsl2的请参照以下链接自行安装:
https://docs.microsoft/en-us/windows/wsl/install-win10
安装windows Terminal
-
打开微软应用商店,搜索“Terminal”,安装,打开后的界面是这样的:
-
默认打开的是 PownerShell 终端,我们可以设置为默认打开 Ubuntu 终端。点击标签右边的下拉三角,选择设置:
-
然后会打开一个json文件,Ctrl+F 搜索Ubuntu 将搜索到的 “name”: “Ubuntu-20.04” 的 guid 复制
-
将guid的值 粘贴到文件开头的
defaultProfile
的值:
-
然后保存重新打开Terminal 就是默认ubuntu终端了
接下来开始配置 oh-my-zsh
- 安装zsh
1.先看下自己有哪一些 shell
cat /etc/shells
2.如果没有 zsh 需要安装
sudo apt-get install zsh #Ubuntu Linux 记得先升级下 apt-get
sudo yum install zsh #Redhat Linux
3.安装完成后设置zsh 为默认shell
chsh -s /bin/zsh #安装完成后设置当前用户使用 zsh 并重启 wsl
- 安装oh-my-zsh
# 一键安装脚本命令:
sh -c "$(curl -fsSL https://raw.githubusercontent/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# 以上脚本可能会报错 curl: (7) Failed to connect to raw.githubusercontent port 443: Connection refused
# 解决方案:
1.在https://www.ipaddress/ 查询raw.githubuercontent的真实IP
2.打开win10资源管理器输入以下地址 C:\Windows\System32\drivers\etc\ 将hosts文件拷贝到桌面打开
3.将 199.232.96.133 raw.githubusercontent 拷贝到hosts文件最下面保存
4.将桌面的hosts文件替换 路径 C:\Windows\System32\drivers\etc\ 下的 hosts
# 修改 Oh My Zsh 主题
sed -i '/^ZSH_THEME=/c\ZSH_THEME="agnoster"' ~/.zshrc
source ~/.zshrc
# 安装 Oh My Zsh 插件
1.安装 zsh-syntax-highlighting(代码高亮)
git clone https://github/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
2.安装 zsh-autosuggestions(自动建议)
git clone https://github/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
3.安装 zsh-completions(自动补全)
git clone https://github/zsh-users/zsh-completions $ZSH_CUSTOM/plugins/zsh-completions
4.zsh-completions 插件需要将 autoload -U compinit && compinit 添加到.zshrc,输入命令可一键添加:
[ -z "`grep "autoload -U compinit && compinit" ~/.zshrc`" ] && echo "autoload -U compinit && compinit" >> ~/.zshrc
5.把需要启用的插件写入到配置文件中,使用 sed 命令一键操作:
sed -i '/^plugins=/c\plugins=(git sudo z zsh-syntax-highlighting zsh-autosuggestions zsh-completions)' ~/.zshrc
6.最后应用配置
source ~/.zshrc
配置ubuntu打开windows程序
- 安装oh-my-zsh后再打开windows程序可能会报错找不到路径
- 例如: 未安装zsh之前 终端输入notepad.exe 可以打开win10 的记事本,安装zsh后可能会报错
zsh: command not found:
这是因为zsh未加载windows的环境变量
解决 zsh: command not found: 方案
将win系统相应程序路径添加到 .zshrc文件内 打开.zshrc
vim ~/.zshrc
格式为:
export PATH=/mnt/d/Program\ Files/JetBrains/PyCharm\ Community\ Edition\ 2020.2/bin:/mnt/c/Program\ Files\ (x86)/Tencent/WeChat:/mnt/c/Program\ Files\ (x86)/Tencent/QQ/Bin
注释:
需要注意的是windows下的 路径 "\" 要换成 "/", 另外空格需要转义 加"\"
多个路径用 ":" 隔开
ubuntu打开windows程序 去除.exe 启动
- 正常情况下ubuntu配置win10 环境变量后 启动win程序 需要带.exe 才可以
- 接下来配置不加.exe启动windows程序
一、建议的方案有两种
1.单个win程序 可以使用别名的方式
# 打开.zshrc
vim ~/.zshrc
# 将以下命令添加到.zshrc
alias 别名=程序名.exe 例如: alias adb=adb.exe
2.多个win程序需要添加则使用以下命令
# 打开.zshrc 将命令添加到 .zshrc
vim ~/.zshrc
command_not_found_handler() {
if cmd.exe /c "(where $1 || (help $1 |findstr /V Try)) >nul 2>nul && ($* || exit 0)"; then
return $?
else
[[ -x /usr/lib/command-not-found ]] || return 1
/usr/lib/command-not-found --no-failure-msg -- ${1+"$1"} && :
fi
}
-
以上两种方案优缺点:
- 第一种适合只更改少量exe程序
- 第二种适合多个exe程序需要修改
-
如果使用第二种方案终端可能会出现
UNC 路径不受支持...
的提示,解决方案请往下看
-
在注册表中,添加一个值即可.路径如下:HKEY_CURRENT_USER\Software\Microsoft\Command Processor添加值 DisableUNCCheck,类型为 REG_DWORD 并将该值设置为1 (十六进制)。
以上就是本人体验win10 下wsl的全过程配置,加一张配置完成的图
版权声明:本文标题:win10 + Terminal + WSL+ oh-my-zsh 配置漂亮实用的windows终端及配置ubuntu不加.exe打开windows程序 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1725830502a1044547.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论