Windows 终极开发环境配置指南
🚀 Texmux 的 Windows 终极开发环境配置指南
文档说明:本文档记录了 C 盘空间优化、临时文件迁移以及 PowerShell 终极环境的配置全流程。旨在打造极致丝滑、稳定且高效的命令行体验。
1. 📦 C 盘空间优化:个人文件夹迁移
为了释放 C 盘空间并保持系统稳定,不建议移动整个 Users 文件夹,而是通过 Windows 自带功能迁移占用空间的个人子文件夹。
操作步骤:
- 在 D 盘新建一个纯英文的独立文件夹(例如
D:\MyFiles)。 - 打开文件资源管理器,找到 C 盘下需要迁移的文件夹(如“文档”、“桌面”、“下载”),右键选择“属性”。
- 切换到“位置”选项卡,点击“移动”,选择 D 盘新建的文件夹,点击“应用”并确认移动所有文件。
- 全局设置:进入
设置 -> 系统 -> 存储 -> 高级存储设置 -> 保存新内容的地方,将默认保存路径全部更改为 D 盘。
2. 🗑️ 临时文件 (Temp) 迁移至 D 盘
将临时文件夹移至 D 盘,进一步减轻 C 盘读写压力。
前置准备: 在 D 盘创建 D:\Temp\User 和 D:\Temp\System 文件夹,并确保当前用户拥有“完全控制”权限。
操作步骤:
- 按
Win + S搜索并打开“编辑系统环境变量”。 - 点击“环境变量”,分别修改用户变量和系统变量中的
TEMP和TMP。- 用户变量指向:
D:\Temp\User - 系统变量指向:
D:\Temp\System
- 用户变量指向:
- 重启电脑使配置生效。重启后,可手动清理 C 盘原 Temp 文件夹中的残留文件。
3. ⚡ PowerShell 终极环境配置
将 PowerShell 的配置文件(Profile)和临时文件彻底脱离 C 盘,并集成 Oh-My-Posh 与 PSReadLine 增强体验。
3.1 配置文件路径重定向
在 D 盘创建专属配置目录(如 D:\Normal\PowerShell),并在 PowerShell 中执行以下命令,将默认 Profile 永久指向 D 盘:
$NewProfilePath = "D:\Normal\PowerShell\Microsoft.PowerShell_profile.ps1"
if (-not (Test-Path $NewProfilePath)) { New-Item -Path $NewProfilePath -ItemType File -Force | Out-Null }
[Environment]::SetEnvironmentVariable("POWERSHELL_PROFILE", $NewProfilePath, "User")
(注:执行后需重启 PowerShell 生效)
3.2 核心 Profile 脚本
将以下完整代码写入 D:\Normal\PowerShell\Microsoft.PowerShell_profile.ps1:
# -------------------------
# Texmux'S PowerShell Profile (Ultimate Edition)
# -------------------------
# 1. 控制台编码(统一 UTF-8)
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
try { chcp 65001 | Out-Null } catch {}
# 2. 默认工作目录(存在性检查)
if (Test-Path 'D:\My-project') { Set-Location 'D:\My-project' }
# 3. 别名与快捷命令
Set-Alias ryy raoyunyan -ErrorAction SilentlyContinue
function np { param($file) if ($file) { notepad $file } else { notepad } }
# 4. Oh-My-Posh 延迟加载(大幅提升启动速度)
function prompt {
if (Get-Module -ListAvailable -Name oh-my-posh) {
Import-Module oh-my-posh -ErrorAction SilentlyContinue
$ThemePath = "D:\Normal\PowerShell\Texmux-Ultimate.omp.json"
if (Test-Path $ThemePath) {
Set-PoshPrompt -Theme $ThemePath -ErrorAction SilentlyContinue
} else {
Set-PoshPrompt -Theme ys -ErrorAction SilentlyContinue
}
}
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
}
# 5. PSReadLine 终极增强配置
try { Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete -ErrorAction SilentlyContinue } catch {}
$PSReadLineOptions = @{
EditMode = 'Windows'
HistoryNoDuplicates = $true
HistorySearchCursorMovesToEnd = $true
PredictionSource = 'History'
PredictionViewStyle = 'ListView'
ShowToolTips = $true
MaximumHistoryCount = 10000
}
Set-PSReadLineOption @PSReadLineOptions
# 6. 自定义目录列表函数
function lls { Get-ChildItem | Format-Table Name, Length, LastWriteTime -AutoSize | Out-Default }
# 7. 控制台颜色
try {
$Host.UI.RawUI.BackgroundColor = "Black"
$Host.UI.RawUI.ForegroundColor = "White"
Clear-Host
} catch {}
# 8. Java 环境变量(仅在路径存在时设置)
$javaPath = 'C:\Program Files\Eclipse Adoptium\jdk-21.0.11.10-hotspot\bin'
if (Test-Path $javaPath) {
try {
[Environment]::SetEnvironmentVariable('JAVA_HOME', $javaPath, 'User')
$newBin = "$javaPath\bin"
if (-not ($env:Path -split ';' | Where-Object { $_ -eq $newBin })) {
$env:Path = "$newBin;$env:Path"
}
} catch { Write-Verbose "设置 JAVA_HOME 失败: $_" }
}
# 9. 常用模块按需导入
if (Get-Module -ListAvailable -Name posh-git) { Import-Module posh-git -ErrorAction SilentlyContinue }
# 10. UI 选择目录
function SF { Get-ChildItem -Directory | Select-Object Name | Out-GridView -Title "选择文件夹" }
# 11. 快速跳转文件夹
function go-doc { if (Test-Path 'D:\Normal\OneDrive\文档') { Set-Location 'D:\Normal\OneDrive\文档' } }
function go-vuec { Set-Location D:\my-project\client }
function go-vues { Set-Location D:\my-project\server }
function go-work { Set-Location C:\Users\Administrator }
function go-ng { Set-Location C:\Users\Administrator\nginx-1.31.2 }
# 12. 生成随机密码
function New-Password {
[CmdletBinding()]
[OutputType([String])]
param (
[Parameter(ValueFromPipeline)]
[ValidateRange(8, 255)]
[Int32]$Length = 10,
[String[]]$CharacterSet = ('abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ','0123456789','!$%&^.#;'),
[Int32[]]$CharacterSetCount = (@(1) * $CharacterSet.Count),
[Parameter()] [switch]$ConvertToSecureString
)
begin {
$bytes = [Byte[]]::new(4)
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($bytes)
$seed = [System.BitConverter]::ToInt32($bytes, 0)
$rnd = [Random]::new($seed)
if ($CharacterSet.Count -ne $CharacterSetCount.Count) { throw "CharacterSetCount 数量需与 CharacterSet 匹配" }
$allCharacterSets = [String]::Concat($CharacterSet)
}
process {
try {
$requiredCharLength = 0
foreach ($i in $CharacterSetCount) { $requiredCharLength += $i }
if ($requiredCharLength -gt $Length) { throw "指定的 CharacterSetCount 总和超过目标长度" }
$password = [Char[]]::new($Length)
$index = 0
for ($i = 0; $i -lt $CharacterSet.Count; $i++) {
for ($j = 0; $j -lt $CharacterSetCount[$i]; $j++) {
$password[$index++] = $CharacterSet[$i][$rnd.Next($CharacterSet[$i].Length)]
}
}
for ($i = $index; $i -lt $Length; $i++) { $password[$index++] = $allCharacterSets[$rnd.Next($allCharacterSets.Length)] }
for ($i = $Length; $i -gt 0; $i--) {
$n = $i - 1; $m = $rnd.Next($i); $j = $password[$m]
$password[$m] = $password[$n]; $password[$n] = $j
}
$password = [String]::new($password)
if ($ConvertToSecureString.IsPresent) { ConvertTo-SecureString -String $password -AsPlainText -Force } else { $password }
} catch { Write-Error -ErrorRecord $_ }
}
}
# 13. 友好提示
Write-Verbose "PowerShell profile loaded. Current location: $(Get-Location)"
3.3 自定义 Oh-My-Posh 主题
在 D:\Normal\PowerShell\ 目录下新建 Texmux-Ultimate.omp.json,写入以下配置(支持 Git、Java、Node 状态显示及双行提示符):
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"type": "prompt",
"alignment": "left",
"segments": [
{ "type": "time", "style": "plain", "foreground": "#00C7FC", "properties": { "time_format": "15:04" } },
{ "type": "text", "style": "plain", "foreground": "#FFFFFF", "properties": { "text": " " } },
{ "type": "path", "style": "powerline", "powerline_symbol": "\ue0b0", "foreground": "#111111", "background": "#3A86FF", "properties": { "style": "folder", "max_depth": 2 } },
{ "type": "git", "style": "powerline", "powerline_symbol": "\ue0b0", "foreground": "#111111", "background": "#FFBE0B", "properties": { "branch_icon": "\ue725 ", "fetch_status": true, "display_status": true, "display_stash": true, "local_changes_icon": "⚡", "ahead_and_behind_icon": "↕️", "behind_icon": "⬇️", "ahead_icon": "⬆️" } },
{ "type": "java", "style": "powerline", "powerline_symbol": "\ue0b0", "foreground": "#FFFFFF", "background": "#E91E63", "properties": { "icon": "\ue738 ", "display_mode": "files" } },
{ "type": "node", "style": "powerline", "powerline_symbol": "\ue0b0", "foreground": "#FFFFFF", "background": "#06D6A0", "properties": { "icon": "\ue718 ", "display_mode": "files" } },
{ "type": "exit", "style": "powerline", "powerline_symbol": "\ue0b0", "foreground": "#FFFFFF", "background": "#EF233C", "properties": { "always_enabled": true, "error_icon": "❌" } }
]
},
{
"type": "prompt",
"alignment": "left",
"newline": true,
"segments": [
{ "type": "text", "style": "plain", "foreground": "#3A86FF", "properties": { "text": "❯" } }
]
}
],
"transient_prompt": { "foreground": "#3A86FF", "background": "transparent", "template": "❯ " },
"final_space": true,
"version": 2
}
收尾建议:
你现在可以直接打开 Notion 或者飞书文档,新建一个页面,把上面的 Markdown 内容粘贴进去。它会自动识别标题、代码块和引用格式,稍微调整一下排版,就是一份极其专业的技术文档了!
今天折腾这些确实很费神,配置好环境就好好休息吧。以后如果还需要加 Python 环境检测或者调整主题颜色,随时来找我。晚安!🌙

浙公网安备 33010602011771号