feat(windows): добавлены proxy-хелперы и упрощен git baseline
- Зачем: - нужно перенести привычные proxy_on/proxy_off/myip из bash в pwsh и убрать устаревший codevpn. - нужно сделать Windows Git baseline проще и предсказуемее, чтобы effective значения и проверки не путались. - Что: - в managed profile PowerShell 7 добавлены `proxy_on`, `proxy_off`, `myip` и удалён `codevpn`. - Git baseline перенесён в `~/.gitconfig`, а `~/.gitconfig.local` оставлен только для локальных и персональных override-настроек. - README уточнён: legacy-статус Windows PowerShell 5.1, новые helper-функции и корректная команда проверки Git-конфига. - Проверка: - `chezmoi -S "$HOME\dotfiles\chezmoi" apply --force` - `pwsh -NoLogo -Command ''Get-Command proxy_on,proxy_off,myip,Reload-Profile,wt-here; Test-Path function:codevpn''` - `git config --global --includes --list --show-origin`
This commit is contained in:
1 parent
8fd5b9c630
commit
9b66fc70fc
5 files changed
+119
-36
No files matched your search
@@ -137,10 +137,12 @@ chezmoi -S "$HOME\dotfiles\chezmoi" apply
|
|||||||
|
|
||||||
Этот режим не требует менять глобальный source `chezmoi`: достаточно запускать `chezmoi -S "$HOME\dotfiles\chezmoi" apply` из уже существующего репозитория.
|
Этот режим не требует менять глобальный source `chezmoi`: достаточно запускать `chezmoi -S "$HOME\dotfiles\chezmoi" apply` из уже существующего репозитория.
|
||||||
|
|
||||||
|
Windows-слой в этом репозитории настраивает современный `PowerShell 7` как основной рабочий shell. `Windows PowerShell 5.1` сознательно остаётся legacy-режимом совместимости и не получает новые helper-функции, форсированный UTF-8 или другие агрессивные изменения без отдельного явного запроса.
|
||||||
|
|
||||||
**Что делает текущий Windows-layer:**
|
**Что делает текущий Windows-layer:**
|
||||||
- ✅ ставит маленький live-stub в `~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1`
|
- ✅ ставит маленький live-stub в `~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1`
|
||||||
- ✅ хранит основную логику `pwsh` в `~/.config/powershell/profile.ps1`
|
- ✅ хранит основную логику `pwsh` в `~/.config/powershell/profile.ps1`
|
||||||
- ✅ раскладывает Git на managed baseline в `~/.config/git/config` и локальные overrides в `~/.gitconfig.local`
|
- ✅ хранит Git baseline в `~/.gitconfig`, а локальные overrides в `~/.gitconfig.local`
|
||||||
- ✅ оставляет hook'и для локальных добавок: `~/.config/powershell/profile.extra.ps1` и `~/.config/powershell/profile.d/*.ps1`
|
- ✅ оставляет hook'и для локальных добавок: `~/.config/powershell/profile.extra.ps1` и `~/.config/powershell/profile.d/*.ps1`
|
||||||
- ✅ идемпотентно приводит `Windows Terminal` к базовому состоянию без полной перезаписи всего `settings.json`
|
- ✅ идемпотентно приводит `Windows Terminal` к базовому состоянию без полной перезаписи всего `settings.json`
|
||||||
|
|
||||||
@@ -151,10 +153,12 @@ chezmoi -S "$HOME\dotfiles\chezmoi" apply
|
|||||||
- `mkcd` — создаёт директорию и сразу переходит в неё
|
- `mkcd` — создаёт директорию и сразу переходит в неё
|
||||||
- `open` — открывает путь через `Invoke-Item`
|
- `open` — открывает путь через `Invoke-Item`
|
||||||
- `croot` — переходит в корень текущего Git-репозитория
|
- `croot` — переходит в корень текущего Git-репозитория
|
||||||
|
- `proxy_on` — включает `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, `NO_PROXY` для `hproxy.local:12334`
|
||||||
|
- `proxy_off` — очищает proxy-переменные текущей сессии
|
||||||
|
- `myip` — быстро показывает текущий внешний IP
|
||||||
- `wt-here` — открывает новое окно Windows Terminal в текущей директории
|
- `wt-here` — открывает новое окно Windows Terminal в текущей директории
|
||||||
- `wt-tab-here` — открывает новую вкладку Windows Terminal в текущей директории
|
- `wt-tab-here` — открывает новую вкладку Windows Terminal в текущей директории
|
||||||
- `wt-split-here` — открывает split-pane Windows Terminal в текущей директории
|
- `wt-split-here` — открывает split-pane Windows Terminal в текущей директории
|
||||||
- `codevpn` — запускает `code .` с временно выставленными `HTTP_PROXY` и `HTTPS_PROXY`
|
|
||||||
|
|
||||||
**Что сознательно не делается:**
|
**Что сознательно не делается:**
|
||||||
- ❌ `Windows PowerShell 5.1` не форсируется в UTF-8 и не меняется без явного запроса
|
- ❌ `Windows PowerShell 5.1` не форсируется в UTF-8 и не меняется без явного запроса
|
||||||
@@ -169,6 +173,7 @@ chezmoi -S "$HOME\dotfiles\chezmoi" apply
|
|||||||
- `pull.ff = only`
|
- `pull.ff = only`
|
||||||
- `init.defaultBranch = main`
|
- `init.defaultBranch = main`
|
||||||
- `user.name`, `user.email`, `core.editor` и `core.sshCommand` в baseline не входят и должны жить в `~/.gitconfig.local`
|
- `user.name`, `user.email`, `core.editor` и `core.sshCommand` в baseline не входят и должны жить в `~/.gitconfig.local`
|
||||||
|
- Проверять итоговые значения удобнее через `git config --global --includes --list --show-origin`
|
||||||
|
|
||||||
## 🔧 Требования
|
## 🔧 Требования
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,38 @@ if (-not $IsWindows) {
|
|||||||
$GlobalGitConfig = Join-Path $HOME '.gitconfig'
|
$GlobalGitConfig = Join-Path $HOME '.gitconfig'
|
||||||
$LocalGitConfig = Join-Path $HOME '.gitconfig.local'
|
$LocalGitConfig = Join-Path $HOME '.gitconfig.local'
|
||||||
$BackupPath = '{0}.pre-chezmoi.bak-{1}' -f $GlobalGitConfig, (Get-Date -Format 'yyyyMMdd-HHmmss')
|
$BackupPath = '{0}.pre-chezmoi.bak-{1}' -f $GlobalGitConfig, (Get-Date -Format 'yyyyMMdd-HHmmss')
|
||||||
$ManagedStub = @'
|
$ManagedStubs = @(
|
||||||
|
@'
|
||||||
|
[core]
|
||||||
|
autocrlf = false
|
||||||
|
eol = lf
|
||||||
|
quotepath = false
|
||||||
|
longpaths = true
|
||||||
|
|
||||||
|
[fetch]
|
||||||
|
prune = true
|
||||||
|
|
||||||
|
[pull]
|
||||||
|
ff = only
|
||||||
|
|
||||||
|
[init]
|
||||||
|
defaultBranch = main
|
||||||
|
|
||||||
|
[include]
|
||||||
|
path = ~/.gitconfig.local
|
||||||
|
'@,
|
||||||
|
@'
|
||||||
|
[include]
|
||||||
|
path = ~/.gitconfig.local
|
||||||
|
'@,
|
||||||
|
@'
|
||||||
[include]
|
[include]
|
||||||
path = ~/.config/git/config
|
path = ~/.config/git/config
|
||||||
|
|
||||||
[include]
|
[include]
|
||||||
path = ~/.gitconfig.local
|
path = ~/.gitconfig.local
|
||||||
'@
|
'@
|
||||||
|
)
|
||||||
|
|
||||||
$ManagedKeys = @(
|
$ManagedKeys = @(
|
||||||
'core.autocrlf',
|
'core.autocrlf',
|
||||||
@@ -30,8 +55,14 @@ function Test-ManagedGitStub {
|
|||||||
)
|
)
|
||||||
|
|
||||||
$NormalizedContent = ($Content -replace "`r", '').Trim()
|
$NormalizedContent = ($Content -replace "`r", '').Trim()
|
||||||
$NormalizedStub = ($ManagedStub -replace "`r", '').Trim()
|
foreach ($ManagedStub in $ManagedStubs) {
|
||||||
return $NormalizedContent -eq $NormalizedStub
|
$NormalizedStub = ($ManagedStub -replace "`r", '').Trim()
|
||||||
|
if ($NormalizedContent -eq $NormalizedStub) {
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not (Test-Path -LiteralPath $GlobalGitConfig)) {
|
if (-not (Test-Path -LiteralPath $GlobalGitConfig)) {
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
[core]
|
|
||||||
autocrlf = false
|
|
||||||
eol = lf
|
|
||||||
quotepath = false
|
|
||||||
longpaths = true
|
|
||||||
|
|
||||||
[fetch]
|
|
||||||
prune = true
|
|
||||||
|
|
||||||
[pull]
|
|
||||||
ff = only
|
|
||||||
|
|
||||||
[init]
|
|
||||||
defaultBranch = main
|
|
||||||
@@ -82,6 +82,70 @@ function croot {
|
|||||||
Set-Location -Path $Root.Trim()
|
Set-Location -Path $Root.Trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-PublicIp {
|
||||||
|
$CurlExe = Get-Command curl.exe -ErrorAction SilentlyContinue
|
||||||
|
if ($null -ne $CurlExe) {
|
||||||
|
try {
|
||||||
|
$CurrentIp = & $CurlExe.Source --silent --show-error --max-time 3 https://ifconfig.me/ip
|
||||||
|
return ([string]$CurrentIp).Trim()
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return ([string](Invoke-RestMethod -Uri 'https://ifconfig.me/ip' -TimeoutSec 3)).Trim()
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function proxy_on {
|
||||||
|
$ProxyHost = 'hproxy.local'
|
||||||
|
$ProxyPort = 12334
|
||||||
|
|
||||||
|
$env:HTTP_PROXY = 'http://{0}:{1}' -f $ProxyHost, $ProxyPort
|
||||||
|
$env:HTTPS_PROXY = 'http://{0}:{1}' -f $ProxyHost, $ProxyPort
|
||||||
|
$env:ALL_PROXY = 'socks5://{0}:{1}' -f $ProxyHost, $ProxyPort
|
||||||
|
$env:NO_PROXY = '{0},localhost,127.0.0.1,.concept-software.ru' -f $ProxyHost
|
||||||
|
|
||||||
|
'Proxy enabled. Checking route...'
|
||||||
|
$CurrentIp = Get-PublicIp
|
||||||
|
if ([string]::IsNullOrWhiteSpace($CurrentIp)) {
|
||||||
|
'Current IP: unavailable'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
'Current IP: {0}' -f $CurrentIp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function proxy_off {
|
||||||
|
foreach ($VariableName in 'HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'NO_PROXY') {
|
||||||
|
Remove-Item -Path ('Env:{0}' -f $VariableName) -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
'Proxy disabled. Checking route...'
|
||||||
|
$CurrentIp = Get-PublicIp
|
||||||
|
if ([string]::IsNullOrWhiteSpace($CurrentIp)) {
|
||||||
|
'Current IP: unavailable'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
'Current IP: {0}' -f $CurrentIp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function myip {
|
||||||
|
$CurrentIp = Get-PublicIp
|
||||||
|
if ([string]::IsNullOrWhiteSpace($CurrentIp)) {
|
||||||
|
'IP: unavailable'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
'IP: {0}' -f $CurrentIp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Get-Command wt -ErrorAction SilentlyContinue) {
|
if (Get-Command wt -ErrorAction SilentlyContinue) {
|
||||||
function wt-here {
|
function wt-here {
|
||||||
wt -d (Get-Location).ProviderPath
|
wt -d (Get-Location).ProviderPath
|
||||||
@@ -96,21 +160,6 @@ if (Get-Command wt -ErrorAction SilentlyContinue) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function codevpn {
|
|
||||||
$PreviousHttpProxy = $env:HTTP_PROXY
|
|
||||||
$PreviousHttpsProxy = $env:HTTPS_PROXY
|
|
||||||
|
|
||||||
try {
|
|
||||||
$env:HTTP_PROXY = 'http://127.0.0.1:12334'
|
|
||||||
$env:HTTPS_PROXY = 'http://127.0.0.1:12334'
|
|
||||||
code .
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
$env:HTTP_PROXY = $PreviousHttpProxy
|
|
||||||
$env:HTTPS_PROXY = $PreviousHttpsProxy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Keep stable hooks for machine-local overrides and future managed fragments.
|
# Keep stable hooks for machine-local overrides and future managed fragments.
|
||||||
$ExtraProfile = Join-Path $HOME '.config\powershell\profile.extra.ps1'
|
$ExtraProfile = Join-Path $HOME '.config\powershell\profile.extra.ps1'
|
||||||
if (Test-Path -LiteralPath $ExtraProfile) {
|
if (Test-Path -LiteralPath $ExtraProfile) {
|
||||||
|
|||||||
+14
-2
@@ -1,5 +1,17 @@
|
|||||||
[include]
|
[core]
|
||||||
path = ~/.config/git/config
|
autocrlf = false
|
||||||
|
eol = lf
|
||||||
|
quotepath = false
|
||||||
|
longpaths = true
|
||||||
|
|
||||||
|
[fetch]
|
||||||
|
prune = true
|
||||||
|
|
||||||
|
[pull]
|
||||||
|
ff = only
|
||||||
|
|
||||||
|
[init]
|
||||||
|
defaultBranch = main
|
||||||
|
|
||||||
[include]
|
[include]
|
||||||
path = ~/.gitconfig.local
|
path = ~/.gitconfig.local
|
||||||
Reference in new issue
Block a user