Windows11优化

youncyb 发布于 22 天前 97 次阅读 环境搭建


本指南旨在帮助用户通过一系列优化和美化设置,提升 Windows 11 的性能和用户体验。从禁用不必要的启动项、优化视觉效果到调整隐私设置,我们将逐步引导您完成系统优化。此外,还提供了美化 Windows Terminal 的方法,使终端界面更具现代感与个性化,提升日常使用的观感。

1. 终端优化

0. 效果图

image-20220119095628725

image-20220304115012390

1. 安装 Windows Terminal

打开微软商店安装 Windows Terminal

image-20220119094939086

安装字体:Hack Nerd Font Mono

2. 安装插件

posh 类似 Linux 上的 zsh。

安装 posh 前先设置代理,不然导致网速较慢。用 vscode 编辑$PROFILE

code $PROFILE

添加:

$regPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'

function Clear-Proxy
{
    Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0
    Set-ItemProperty -Path $regPath -Name ProxyServer -Value ''
    Set-ItemProperty -Path $regPath -Name ProxyOverride -Value ''

    [Environment]::SetEnvironmentVariable('http_proxy', $null, 'User')
    [Environment]::SetEnvironmentVariable('https_proxy', $null, 'User')
    [Environment]::SetEnvironmentVariable('HTTP_PROXY', $null, 'User')
    [Environment]::SetEnvironmentVariable('HTTPS_PROXY', $null, 'User')

}

function Set-Proxy
{
    $proxy = 'http://127.0.0.1:7890'

    Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
    Set-ItemProperty -Path $regPath -Name ProxyServer -Value $proxy
    Set-ItemProperty -Path $regPath -Name ProxyOverride -Value '<local>'

    [Environment]::SetEnvironmentVariable('http_proxy', $proxy, 'User')
    [Environment]::SetEnvironmentVariable('https_proxy', $proxy, 'User')
    [Environment]::SetEnvironmentVariable('HTTP_PROXY', $null, 'User')
    [Environment]::SetEnvironmentVariable('HTTPS_PROXY', $null, 'User')
}

重新打开 terminal,验证:

set-proxy #开启代理
curl -uri ipinfo.io -UseBasicParsing  #通过ipinfo.io验证ip

# 安装scoop,windows下的包管理工具
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

# 安装oh-my-posh
scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json

管理员运行,设置 powershell 执行策略,以免脚本被拦截

set-executionpolicy remotesigned

安装 posh-git、oh-my-posh、DirColors

Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Install-Module DirColors -Scope CurrentUser 

3. 编辑$PROFILE

导入模块,并设置 posh 主题(old 方式):

Import-Module DirColors
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme JanDeDobbeleer

4. 修改 Terminal 配置

在 defaults 中添加:

"acrylicOpacity": 0.1, //背景透明度(0-1)
"useAcrylic": true, // 启用毛玻璃
"backgroundImage": "c://xxx//1.png", //背景图片
"backgroundImageOpacity": 0.9, //图片透明度(0-1)
"experimental.retroTerminalEffect": false, //复古的CRT 效果
"backgroundImageStretchMode": "uniformToFill", //背景图片填充模式
"font": {
"face":"Hack Nerd Font Mono", //字体
"size": 12, //文字大小
"weight": "thin" //文字宽度,可设置加粗
},
"colorScheme": "Campbell", //主题名字
"cursorColor": "#FFFFFF", //光标颜色
"cursorShape": "bar", //光标形状
"antialiasingMode": "cleartype" //消除文字锯齿

5. 命令自动补全

Install-Module -Name PowerShellGet -Force -Scope CurrentUser
Install-Module PSReadLine -Force -Scope CurrentUser

然后修改$PROFILE,既可以上下键补全历史命令

# 设置自动补全
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward

Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

6. 其他设置

python2 pip 报错:

LookupError: unknown encoding: cp65001

设置编码,在$PROFILE 文件中添加:

$env:PYTHONIOENCODING = "UTF-8"

7. 最终$Profile 配置

# ========================= Import Module =======================
# 设置posh主题
# Import-Module DirColors
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme amro



# 设置环境变量
$env:PYTHONIOENCODING = "UTF-8"

# ========================= PSReadLine =======================
# 设置自动补全
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Set-PSReadLineKeyHandler -Key Ctrl+a -Function BeginningOfLine
Set-PSReadLineKeyHandler -Key Ctrl+e -Function EndOfLine

# 设置每次回溯历史命令时,光标在末尾
Set-PSReadLineOption -HistorySearchCursorMovesToEnd

# 使用历史纪录 来应用自动补全
Set-PSReadLineOption -PredictionSource History

# 设置 Tab 为补全的快捷键
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete

# 设置 Ctrl + Z 为撤销
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo


# ========================= socks代理设置(弃用,可使用proxychains for windows) =======================
# 设置http代理
$regPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'

function Clear-Proxy
{
    Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0
    Set-ItemProperty -Path $regPath -Name ProxyServer -Value ''
    Set-ItemProperty -Path $regPath -Name ProxyOverride -Value ''

    [Environment]::SetEnvironmentVariable('http_proxy', $null, 'User')
    [Environment]::SetEnvironmentVariable('https_proxy', $null, 'User')
    [Environment]::SetEnvironmentVariable('HTTP_PROXY', $null, 'User')
    [Environment]::SetEnvironmentVariable('HTTPS_PROXY', $null, 'User')

}

function Set-Proxy
{
    $proxy = 'http://127.0.0.1:7890'

    Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
    Set-ItemProperty -Path $regPath -Name ProxyServer -Value $proxy
    Set-ItemProperty -Path $regPath -Name ProxyOverride -Value '<local>'

    [Environment]::SetEnvironmentVariable('http_proxy', $proxy, 'User')
    [Environment]::SetEnvironmentVariable('https_proxy', $proxy, 'User')
    [Environment]::SetEnvironmentVariable('HTTP_PROXY', $null, 'User')
    [Environment]::SetEnvironmentVariable('HTTPS_PROXY', $null, 'User')
}

8. 安装 git bash

git bash 可当做补全一些常用的 Linux 命令。首先下载 git for windows

https://gitforwindows.org/

8.1 解决闪屏问题和历史命令补全

在 ~/.inputrc (如果不存在就创建) 里面添加这样一行:

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on
set bell-style none 

bash 运行:bind -f ~/.inputrc

8.2 git bash 美化

像上文中安装 oh-my-posh,然后将 oh-my-posh.exe 加入环境变量的 PATH。首先,powershell 通过 $env:POSH_PATH 获取 oh-my-posh.exe 路径。

然后加入环境变量。

vscode 编辑:code ~/.bash_profile,加入:

eval "$(oh-my-posh --init --shell bash --config ~/AppData/Local/oh-my-posh/themes/microverse-power.omp.json)"

bash 运行:source ~/.bash_profile

8.3 windows terminal git bash 配置

安装完毕后,在 Windows terminal 的配置文件 profiles->lists 加入:

{
  "commandline": "%PROGRAMFILES%/Git/bin/bash.exe -i -l",
  "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed23}",
  "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
  "hidden": false,
  "name": "Git Bash"
}

9. 最终的 windows terminal 配置

{
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "actions": 
    [
        {
            "command": 
            {
                "action": "copy",
                "singleLine": false
            },
            "keys": "ctrl+c"
        },
        {
            "command": "find",
            "keys": "ctrl+shift+f"
        },
        {
            "command": "paste",
            "keys": "ctrl+v"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "alt+shift+d"
        }
    ],
    "copyFormatting": "none",
    "copyOnSelect": false,
    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "disableAnimations": true,
    "profiles": 
    {
        "defaults": 
        {
            "antialiasingMode": "cleartype",
            "backgroundImage": "c://hape//1.png",
            "backgroundImageOpacity": 0.90000000000000002,
            "backgroundImageStretchMode": "uniformToFill",
            "colorScheme": "Campbell",
            "cursorColor": "#FFFFFF",
            "cursorShape": "bar",
            "experimental.retroTerminalEffect": false,
            "font": 
            {
                "face": "Hack Nerd Font Mono",
                "size": 12,
                "weight": "thin"
            },
            "useAcrylic": true
        },
        "list": 
        [
            {
                "commandline": "powershell.exe",
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "pwsh"
            },
            {
                "commandline": "cmd.exe",
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "CMD"
            },
            {
                "commandline": "%PROGRAMFILES%/Git/bin/bash.exe -i -l",
                "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed23}",
                "icon": "%PROGRAMFILES%/Git/mingw64/share/git/git-for-windows.ico",
                "hidden": false,
                "name": "Git Bash"
            }
        ]
    },
    "schemes": 
    [
        {
            "background": "#0C0C0C",
            "black": "#0C0C0C",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#3B78FF",
            "brightCyan": "#61D6D6",
            "brightGreen": "#16C60C",
            "brightPurple": "#B4009E",
            "brightRed": "#E74856",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#F9F1A5",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#CCCCCC",
            "green": "#13A10E",
            "name": "Campbell",
            "purple": "#881798",
            "red": "#C50F1F",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#C19C00"
        },
        {
            "background": "#012456",
            "black": "#0C0C0C",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#3B78FF",
            "brightCyan": "#61D6D6",
            "brightGreen": "#16C60C",
            "brightPurple": "#B4009E",
            "brightRed": "#E74856",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#F9F1A5",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#CCCCCC",
            "green": "#13A10E",
            "name": "Campbell Powershell",
            "purple": "#881798",
            "red": "#C50F1F",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#C19C00"
        },
        {
            "background": "#282C34",
            "black": "#282C34",
            "blue": "#61AFEF",
            "brightBlack": "#5A6374",
            "brightBlue": "#61AFEF",
            "brightCyan": "#56B6C2",
            "brightGreen": "#98C379",
            "brightPurple": "#C678DD",
            "brightRed": "#E06C75",
            "brightWhite": "#DCDFE4",
            "brightYellow": "#E5C07B",
            "cursorColor": "#FFFFFF",
            "cyan": "#56B6C2",
            "foreground": "#DCDFE4",
            "green": "#98C379",
            "name": "One Half Dark",
            "purple": "#C678DD",
            "red": "#E06C75",
            "selectionBackground": "#FFFFFF",
            "white": "#DCDFE4",
            "yellow": "#E5C07B"
        },
        {
            "background": "#FAFAFA",
            "black": "#383A42",
            "blue": "#0184BC",
            "brightBlack": "#4F525D",
            "brightBlue": "#61AFEF",
            "brightCyan": "#56B5C1",
            "brightGreen": "#98C379",
            "brightPurple": "#C577DD",
            "brightRed": "#DF6C75",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#E4C07A",
            "cursorColor": "#4F525D",
            "cyan": "#0997B3",
            "foreground": "#383A42",
            "green": "#50A14F",
            "name": "One Half Light",
            "purple": "#A626A4",
            "red": "#E45649",
            "selectionBackground": "#FFFFFF",
            "white": "#FAFAFA",
            "yellow": "#C18301"
        },
        {
            "background": "#3D3F41",
            "black": "#25292A",
            "blue": "#2075C7",
            "brightBlack": "#00FFCC",
            "brightBlue": "#2075C7",
            "brightCyan": "#15968D",
            "brightGreen": "#629655",
            "brightPurple": "#797FD4",
            "brightRed": "#F24840",
            "brightWhite": "#D2D8D9",
            "brightYellow": "#B68800",
            "cursorColor": "#FFFFFF",
            "cyan": "#15968D",
            "foreground": "#D2D8D9",
            "green": "#629655",
            "name": "Solarized Darcula",
            "purple": "#797FD4",
            "red": "#F24840",
            "selectionBackground": "#FFFFFF",
            "white": "#D2D8D9",
            "yellow": "#B68800"
        },
        {
            "background": "#001E27",
            "black": "#002831",
            "blue": "#2176C7",
            "brightBlack": "#475B62",
            "brightBlue": "#708284",
            "brightCyan": "#819090",
            "brightGreen": "#475B62",
            "brightPurple": "#5956BA",
            "brightRed": "#BD3613",
            "brightWhite": "#FCF4DC",
            "brightYellow": "#536870",
            "cursorColor": "#FFFFFF",
            "cyan": "#259286",
            "foreground": "#708284",
            "green": "#738A05",
            "name": "Solarized Dark",
            "purple": "#C61C6F",
            "red": "#D11C24",
            "selectionBackground": "#FFFFFF",
            "white": "#EAE3CB",
            "yellow": "#A57706"
        },
        {
            "background": "#FDF6E3",
            "black": "#002B36",
            "blue": "#268BD2",
            "brightBlack": "#073642",
            "brightBlue": "#839496",
            "brightCyan": "#93A1A1",
            "brightGreen": "#586E75",
            "brightPurple": "#6C71C4",
            "brightRed": "#CB4B16",
            "brightWhite": "#FDF6E3",
            "brightYellow": "#657B83",
            "cursorColor": "#002B36",
            "cyan": "#2AA198",
            "foreground": "#657B83",
            "green": "#859900",
            "name": "Solarized Light",
            "purple": "#D33682",
            "red": "#DC322F",
            "selectionBackground": "#FFFFFF",
            "white": "#EEE8D5",
            "yellow": "#B58900"
        },
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#FFFFFF",
            "cyan": "#06989A",
            "foreground": "#D3D7CF",
            "green": "#4E9A06",
            "name": "Tango Dark",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#FFFFFF",
            "black": "#000000",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#000000",
            "cyan": "#06989A",
            "foreground": "#555753",
            "green": "#4E9A06",
            "name": "Tango Light",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#000080",
            "brightBlack": "#808080",
            "brightBlue": "#0000FF",
            "brightCyan": "#00FFFF",
            "brightGreen": "#00FF00",
            "brightPurple": "#FF00FF",
            "brightRed": "#FF0000",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#FFFF00",
            "cursorColor": "#FFFFFF",
            "cyan": "#008080",
            "foreground": "#C0C0C0",
            "green": "#008000",
            "name": "Vintage",
            "purple": "#800080",
            "red": "#800000",
            "selectionBackground": "#FFFFFF",
            "white": "#C0C0C0",
            "yellow": "#808000"
        }
    ],
    "showTerminalTitleInTitlebar": false,
    "theme": "dark"
}

2. 删除多余组件和广告

2.1 去广告

2024 年 4 月 23 日,微软发布了 Windows 11 的 更新,在整个操作系统中添加了广告,包括文件资源管理器、开始菜单等。

https://github.com/xM4ddy/OFGB

2.2 删除多余组件

删除不必要的系统应用、组件,关闭 windows 自动更新。

https://github.com/LeDragoX/Win-Debloat-Tools

2.3 关闭 windows defender

https://github.com/Tlaster/YourAV //注册fake AV,windows defender会自动关闭
https://github.com/es3n1n/no-defender // 原理同上,已被删库