diff --git a/README.md b/README.md index 50e22e2..f59b14e 100644 --- a/README.md +++ b/README.md @@ -137,10 +137,12 @@ 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:** - ✅ ставит маленький live-stub в `~/Documents/PowerShell/Microsoft.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` - ✅ идемпотентно приводит `Windows Terminal` к базовому состоянию без полной перезаписи всего `settings.json` @@ -151,10 +153,12 @@ chezmoi -S "$HOME\dotfiles\chezmoi" apply - `mkcd` — создаёт директорию и сразу переходит в неё - `open` — открывает путь через `Invoke-Item` - `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-tab-here` — открывает новую вкладку Windows Terminal в текущей директории - `wt-split-here` — открывает split-pane Windows Terminal в текущей директории -- `codevpn` — запускает `code .` с временно выставленными `HTTP_PROXY` и `HTTPS_PROXY` **Что сознательно не делается:** - ❌ `Windows PowerShell 5.1` не форсируется в UTF-8 и не меняется без явного запроса @@ -169,6 +173,7 @@ chezmoi -S "$HOME\dotfiles\chezmoi" apply - `pull.ff = only` - `init.defaultBranch = main` - `user.name`, `user.email`, `core.editor` и `core.sshCommand` в baseline не входят и должны жить в `~/.gitconfig.local` +- Проверять итоговые значения удобнее через `git config --global --includes --list --show-origin` ## 🔧 Требования diff --git a/chezmoi/.chezmoiscripts/run_before_10-migrate-gitconfig.ps1 b/chezmoi/.chezmoiscripts/run_before_10-migrate-gitconfig.ps1 index 5093a5b..f2b99ee 100644 --- a/chezmoi/.chezmoiscripts/run_before_10-migrate-gitconfig.ps1 +++ b/chezmoi/.chezmoiscripts/run_before_10-migrate-gitconfig.ps1 @@ -5,13 +5,38 @@ if (-not $IsWindows) { $GlobalGitConfig = Join-Path $HOME '.gitconfig' $LocalGitConfig = Join-Path $HOME '.gitconfig.local' $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] path = ~/.config/git/config [include] path = ~/.gitconfig.local '@ +) $ManagedKeys = @( 'core.autocrlf', @@ -30,8 +55,14 @@ function Test-ManagedGitStub { ) $NormalizedContent = ($Content -replace "`r", '').Trim() - $NormalizedStub = ($ManagedStub -replace "`r", '').Trim() - return $NormalizedContent -eq $NormalizedStub + foreach ($ManagedStub in $ManagedStubs) { + $NormalizedStub = ($ManagedStub -replace "`r", '').Trim() + if ($NormalizedContent -eq $NormalizedStub) { + return $true + } + } + + return $false } if (-not (Test-Path -LiteralPath $GlobalGitConfig)) { diff --git a/chezmoi/dot_config/git/config b/chezmoi/dot_config/git/config deleted file mode 100644 index 84b4a2e..0000000 --- a/chezmoi/dot_config/git/config +++ /dev/null @@ -1,14 +0,0 @@ -[core] - autocrlf = false - eol = lf - quotepath = false - longpaths = true - -[fetch] - prune = true - -[pull] - ff = only - -[init] - defaultBranch = main diff --git a/chezmoi/dot_config/powershell/profile.ps1 b/chezmoi/dot_config/powershell/profile.ps1 index cceccc1..828763c 100644 --- a/chezmoi/dot_config/powershell/profile.ps1 +++ b/chezmoi/dot_config/powershell/profile.ps1 @@ -82,6 +82,70 @@ function croot { 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) { function wt-here { 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. $ExtraProfile = Join-Path $HOME '.config\powershell\profile.extra.ps1' if (Test-Path -LiteralPath $ExtraProfile) { diff --git a/chezmoi/dot_gitconfig b/chezmoi/dot_gitconfig index a850061..6af265d 100644 --- a/chezmoi/dot_gitconfig +++ b/chezmoi/dot_gitconfig @@ -1,5 +1,17 @@ -[include] - path = ~/.config/git/config +[core] + autocrlf = false + eol = lf + quotepath = false + longpaths = true + +[fetch] + prune = true + +[pull] + ff = only + +[init] + defaultBranch = main [include] path = ~/.gitconfig.local