Back

windows - 安装linux ubuntu ( 使用wsl ) 终端预览 (terminal preview) + git slow的问题

发布时间: 2022-04-22 22:50:00

refer to: https://allthings.how/how-to-use-linux-terminal-in-windows-10/

1. 准备条件

1.1 需要你的设备是win10

1.2 需要开启  wsl

1.3 需要设置默认的wsl version

wsl --set-default-version 2   (管理员权限)

2. 需要你开启windows store ,

参考: https://jingyan.baidu.com/article/4ae03de3b59d223eff9e6b39.html

2.1 以管理员身份运行powser shell, 然后: Get-AppxPackage -allusers | Select Name, PackageFullName

2.2  ctrl + f  搜索  Microsoft.WindowsStore , 找到右侧的值

2.3 power shell 中,运行下面命令(记得根据上面的值做个替换)

Add-appxpackage -register "C:\Program Files\WindowsApps\Microsoft.WindowsStore_11811.1001.18.0_x64__8wekyb3d8bbwe\appxmanifest.xml"-disabledevelopmentmode

3. 打开 win store, 搜索ubuntu, 找到一个下载。 不用登录

4. 运行它。

首次运行时,会看到弹窗,让我们设置用户:

现在你的windows中就有个ubuntu server了。

新创建好的ubuntu无法上网的问题

sudo nano /etc/resolv.conf

refer to: https://stackoverflow.com/questions/62314789/no-internet-connection-on-wsl-ubuntu-windows-subsystem-for-linux

nameserver 8.8.8.8

修改apt source , update !

git 特别慢的问题

修改 .bashrc

前提是需要在windows中安装好 git bash, 这样在wsl中才能有git.exe

这个问题是由于git 的原因造成的,具体见:https://github.com/microsoft/WSL/issues/4401

这个大哥说的非常好哈哈。

解决办法: 在.bashrc中加入这个。

function isWinDir {
  case $PWD/ in
    /mnt/*) return $(true);;
    *) return $(false);;
  esac
}
# wrap the git command to either run windows git or linux
function git {
  if isWinDir
  then
    git.exe "$@"
  else
    /usr/bin/git "$@"
  fi
}

另外,windows下的ls rf 的问题:

 https://stackoverflow.com/questions/5834014/lf-will-be-replaced-by-crlf-in-git-what-is-that-and-is-it-important

修改git config:   ~/.gitconfig 

[core]
  repositoryformatversion = 0
  filemode = false
  bare = false
  logallrefupdates = true
  autocrlf = true


下面是完整的内容(注意我用了socks5 proxy)
[user]
  name = siwei
  email = [email protected]
[core]
  repositoryformatversion = 0
  filemode = false
  bare = false
  logallrefupdates = true
  autocrlf = true
  editor = vim

[push]
  default = matching

[http "https://github.com"]
    proxy = socks5h://192.168.10.50:1090
[https "https://github.com"]
    proxy = socks5h://192.168.10.50:1090

安装终端预览

我也不知道它为啥叫这个名字。 

安装: 在store中搜索 这个名字就可以看到了,也可以在github上找到直接安装。

或者直接下载 github上有。

运行,非常简单。

配置

power shell 的打开, 这里需要用到docker, 所以就 ctrl + shift + g

linux:  ctrl + shift + t

配置打开后的行为:

默认路径,

是否开机启动

(待定: 确定分词的能力)

聚焦窗口: 不要这个东西! 最讨厌别人合并我的窗口了。

设置-> 外观 -> 始终在通知区域显示图标,务必关闭。 这样它就不会合并,并且悄悄的隐藏我们的terminal了。

记得修改preview的语言,使用英文。这样就可以设置 “修改tab标题了,非常重要”

设置tab 颜色: alt + f5
所以,标签和选项卡的问题。。。。中文版的设置在这里。

修改 host 的问题,(修改后记得重启)

win -> notepad -> 右键  -》 管理员打开 -> ctrl +o ->

修改的时候注意: 一个IP地址要放在同一行。例如:

与查看docker host (window) ip地址的办法

在host机器上: ipconfig

在docker 机器上: ifconfig  ,  ping, curl , telnet , 不要省那么点空间, 果断给docker 安装vim, git, ping 等命令。

其他的都不好使。172.17.0.1 啥的,在windows docker上不行。我也不知道为什么。

修改 ubuntu 从WSL 1 成为 WSL2

wsl --list --verbose
wsl --set-default-version 2  (这一句貌似没用)

wsl --set-version Ubuntu-20.04 2  (这一句有用)

如下图所示

Back