# 下载梯子

为了更好的使用 Chocolatey,最好能够有梯子。此处略。

以及记得配置 HTTP_PROXYHTTPS_PROXY

# 下载 Chocolatey

winget 应该不用下载,Chocolatey 需要下载。

参考:Chocolatey Software | Installing Chocolatey (opens new window)

在管理员权限下 Powershell 执行:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

测试是否安装成功:

choco -?

# 为 Chocolatey 配置代理

choco config set proxy "http://localhost:17296/"

# 安装软件

2022.5.27 更新:日常软件还是 winget 比较全,大家贡献起来都很有动力。命令行工具还是 choco 比较全(winget 看起来只支持安装包的软件),开发环境 choco 稍微全一点(比如现在 winget 还没有 jdk18 和 flutter)。

# 搜索 Chocolatey 库

choco info 实在是太慢了,如果自己需要下载软件,不如直接去官网 (opens new window)搜索。

# 安装常用软件

国内软件在 winget 源更新的勤一点,国外软件就直接 choco 装了。

下面的列表按需安装:

# winget 怎么还不支持一次安装多个包
winget install -s winget TIM
winget install -s winget Wechat
winget install -s winget Feishu
winget install -s winget NetEase.CloudMusic

choco install -y `
    potplayer `
    obs-studio.install `
    googlechrome `
    bandizip `
    internet-download-manager `
    steam-client `
    powertoys `
    glasswire `
    fiddler `
    spacesniffer `
    carnac `
    teamviewer `
    synctrayzor `
    zerotier-one `
    geforce-experience # for Nvidia GPU only

如果部分失败了,可以重新执行一遍,Choco 会跳过已经安装的。

# 安装命令行工具

winget install -f -s winget openssh
choco install -y `
    oh-my-posh `
    tldr `
    ffmpeg `
    sudo `
    tcping `
    adb `
    bfg-repo-cleaner `
    mysql-cli `
    iperf3

# 安装开发工具

配置开发环境:

choco install -y `
    jetbrainstoolbox `
    microsoft-windows-terminal wsl wsl-ubuntu-2004 `
    docker-desktop postman git python openjdk llvm nodejs golang powershell-core protoc flutter `
    visualstudio-installer vscode.install

WSL 还得手动去设置添加功能:打开 WSL,然后安装 https://aka.ms/wsl2kernel

配置 pipnpmmaven 的镜像源(在管理员权限下的 Powershell 7 下执行):

pip3 config set global.index-url http://pypi.doubanio.com/simple
pip3 config set global.trusted-host pypi.doubanio.com

npm install -g yarn pnpm --registry=https://registry.npm.taobao.org
# 配置镜像源:https://www.npmjs.com/package/mirror-config-china
npm install -g mirror-config-china --registry=https://registry.npm.taobao.org

mkdir ~/.m2
Invoke-WebRequest -O ~/.m2/settings.xml https://blog.lyh543.cn/mirrors/maven.xml

# 配置 oh-my-posh

Install On Windows | Oh My Posh (opens new window)

在管理员权限下的 PowerShell 7 中执行:

choco install -y oh-my-posh
Install-Module -Scope CurrentUser `
    posh-git, DockerCompletion 

下载 (opens new window)并安装这一堆字体(只安装需要的那两个应该也可以)。修改 Windows Termial 字体为 MesloLGM Nerd Font(某些主题用带 Mono 的字体好一点,有些用不带的好一点,修改主题以后需要自己尝试):

修改 Windows Termial 字体

记得还要修改 VSCode terminal 和 JetBrains IDE 的字体。

顺便也安利一下微软家的 Cascadia Code (opens new window),如果需要可以自行下载。

code $PROFILE,写入以下内容并保存:

# git, docker, choco 的补全模块
Import-Module  posh-git, DockerCompletion
Import-Module$env:ChocolateyInstall\helpers\chocolateyProfile.psm1” -Force
# winget 的补全
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)
        [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
        $Local:word = $wordToComplete.Replace('"', '""')
        $Local:ast = $commandAst.ToString().Replace('"', '""')
        winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
        }
}

# 更多主题:https://ohmyposh.dev/docs/themes
# 我觉得还不错的主题:
# cloud-native-azure
# M365Princess
oh-my-posh.exe init  pwsh --config "$env:POSH_THEMES_PATH/jandedobbeleer.omp.json" | Invoke-Expression

Set-PSReadLineOption -PredictionSource History # 设置预测文本来源为历史记录
# Set-PSReadlineKeyHandler -Key Tab -Function Complete # 设置 Tab 为补全
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete # 设置 Tab 为菜单补全和 Intellisense
# Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete # 设置 Ctrl+d 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo # 设置 Ctrl+z 为撤销
Set-PSReadlineOption -BellStyle None # 禁止补全时的 Beep 声
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -ScriptBlock {
    [Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchBackward()
    [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
}
# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -ScriptBlock {
    [Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchForward()
    [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine()
}

新开的 PowerShell 窗口应该就能看到效果了(第一次需要下载可执行文件,会慢一点)。

新开的 PowerShell 窗口

# 开发相关的配置

# 配置个人 SSH 密钥

略。

以及配置 SSH 走代理:git clone一个github上的仓库,太慢,经常连接失败,但是github官网流畅访问,为什么? - 知乎 (opens new window)

# 允许执行其他 Powershell 脚本

在管理员权限的 Powershell 7 下执行:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Powershell 执行策略

# (个人用)开发工具

在 Powershell 7 下执行:

mkdir ~\git && cd ~\git
mkdir github && cd github
git clone git@github.com:lyh543/dev-tools.git && cd dev-tools
# 添加环境变量
Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1"
Install-ChocolateyPath $PWD.Path

# 更改 Hyper-V 端口

tldr:推荐配置 Hyper-V 只从 40000-49999 的端口范围内选择一部分占用,能避免大部分冲突。

管理员权限下 cmd / Powershell 下执行:

netsh int ipv4 set dynamicport tcp start=40000 num=10000

事情的前因后果可以看这篇文章