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
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user