- Зачем: - нужно перенести стабильную Windows-конфигурацию в dotfiles без поломки существующего stow/install.sh workflow для Linux и WSL. - нужно убрать типичные проблемы Git на Windows, включая line endings, из ручной настройки машины. - Что: - добавлен отдельный source dir `chezmoi/` с tiny stub для PowerShell 7 и managed profile в `~/.config/powershell`. - добавлены идемпотентная настройка Windows Terminal и managed Git baseline с миграцией локальных настроек в `~/.gitconfig.local`. - обновлён README: описан Windows workflow, helper-функции pwsh и состав Git baseline без персональных данных. - Проверка: - `chezmoi -S "$HOME\dotfiles\chezmoi" apply` - `pwsh -NoLogo -Command ''$PSVersionTable.PSVersion.ToString(); chcp; [Console]::InputEncoding.WebName; [Console]::OutputEncoding.WebName''` - `git config --global --includes --list --show-origin`
136 lines
3.7 KiB
PowerShell
136 lines
3.7 KiB
PowerShell
# Keep PowerShell 7 console text I/O on UTF-8 for predictable native tool behavior.
|
|
if ($IsWindows -and $PSVersionTable.PSEdition -eq 'Core' -and $Host.Name -eq 'ConsoleHost') {
|
|
chcp 65001 > $null
|
|
$Utf8NoBom = New-Object System.Text.UTF8Encoding($false)
|
|
[Console]::InputEncoding = $Utf8NoBom
|
|
[Console]::OutputEncoding = $Utf8NoBom
|
|
$OutputEncoding = $Utf8NoBom
|
|
}
|
|
|
|
# Keep interactive editing comfortable without depending on extra prompt frameworks.
|
|
if (
|
|
$Host.Name -eq 'ConsoleHost' -and
|
|
-not [Console]::IsOutputRedirected -and
|
|
$Host.UI.SupportsVirtualTerminal -and
|
|
(Get-Module -ListAvailable -Name PSReadLine)
|
|
) {
|
|
Import-Module PSReadLine -ErrorAction SilentlyContinue
|
|
Set-PSReadLineOption -PredictionSource History -ErrorAction SilentlyContinue
|
|
Set-PSReadLineOption -PredictionViewStyle ListView -ErrorAction SilentlyContinue
|
|
Set-PSReadLineOption -HistoryNoDuplicates:$true -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
function Reload-Profile {
|
|
. $PROFILE
|
|
}
|
|
|
|
function which {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Name
|
|
)
|
|
|
|
Get-Command -Name $Name -All | Select-Object CommandType, Name, Source
|
|
}
|
|
|
|
function touch {
|
|
param(
|
|
[Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)]
|
|
[string[]]$Path
|
|
)
|
|
|
|
foreach ($Item in $Path) {
|
|
if (Test-Path -LiteralPath $Item) {
|
|
(Get-Item -LiteralPath $Item).LastWriteTime = Get-Date
|
|
}
|
|
else {
|
|
New-Item -ItemType File -Path $Item -Force | Out-Null
|
|
}
|
|
}
|
|
}
|
|
|
|
function mkcd {
|
|
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Path
|
|
)
|
|
|
|
New-Item -ItemType Directory -Path $Path -Force | Out-Null
|
|
Set-Location -Path $Path
|
|
}
|
|
|
|
function open {
|
|
param(
|
|
[string]$Path = '.'
|
|
)
|
|
|
|
Invoke-Item -Path $Path
|
|
}
|
|
|
|
function croot {
|
|
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
|
|
Write-Error 'git is not available in PATH.'
|
|
return
|
|
}
|
|
|
|
$Root = git rev-parse --show-toplevel 2>$null
|
|
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($Root)) {
|
|
Write-Error 'Not inside a Git repository.'
|
|
return
|
|
}
|
|
|
|
Set-Location -Path $Root.Trim()
|
|
}
|
|
|
|
if (Get-Command wt -ErrorAction SilentlyContinue) {
|
|
function wt-here {
|
|
wt -d (Get-Location).ProviderPath
|
|
}
|
|
|
|
function wt-tab-here {
|
|
wt -w 0 new-tab -d (Get-Location).ProviderPath
|
|
}
|
|
|
|
function wt-split-here {
|
|
wt -w 0 split-pane -d (Get-Location).ProviderPath
|
|
}
|
|
}
|
|
|
|
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) {
|
|
. $ExtraProfile
|
|
}
|
|
|
|
$ExtraProfileDir = Join-Path $HOME '.config\powershell\profile.d'
|
|
if (Test-Path -LiteralPath $ExtraProfileDir) {
|
|
foreach ($ProfileFragment in (Get-ChildItem -Path $ExtraProfileDir -Filter '*.ps1' -File | Sort-Object Name)) {
|
|
. $ProfileFragment.FullName
|
|
}
|
|
}
|
|
|
|
# Import the Chocolatey Profile that contains the necessary code to enable
|
|
# tab-completions to function for `choco`.
|
|
# Be aware that if you are missing these lines from your profile, tab completion
|
|
# for `choco` will not function.
|
|
# See https://ch0.co/tab-completion for details.
|
|
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
|
|
if (Test-Path -LiteralPath $ChocolateyProfile) {
|
|
Import-Module $ChocolateyProfile
|
|
}
|