diff --git a/.github/workflows/windows-lint.yml b/.github/workflows/windows-lint.yml index c96b2c8..2ad630d 100644 --- a/.github/workflows/windows-lint.yml +++ b/.github/workflows/windows-lint.yml @@ -29,7 +29,8 @@ jobs: uses: microsoft/psscriptanalyzer-action@v1.0 with: path: .\ - recurse: true + recurse: true + excludeRule: '"AvoidUsingWriteHost"' output: results.sarif - name: Upload SARIF results file uses: github/codeql-action/upload-sarif@v2 diff --git a/windows/.files/%LOCALAPPDATA%/nvim b/windows/.files/%LOCALAPPDATA%/nvim index 3c9455b..80068f1 160000 --- a/windows/.files/%LOCALAPPDATA%/nvim +++ b/windows/.files/%LOCALAPPDATA%/nvim @@ -1 +1 @@ -Subproject commit 3c9455bec088aadf22f2bafdb8ae8305559353e0 +Subproject commit 80068f1d230021cfe09b6b59b732dcae9ea8b5bf diff --git a/windows/.files/%USERPROFILE%/.gitconfig b/windows/.files/%USERPROFILE%/.gitconfig new file mode 100644 index 0000000..df363c9 --- /dev/null +++ b/windows/.files/%USERPROFILE%/.gitconfig @@ -0,0 +1,39 @@ +[include] + path = ~/.gitconfig_private + +[filter "lfs"] + smudge = git-lfs smudge -- %f + process = git-lfs filter-process + required = true + clean = git-lfs clean -- %f + +[core] + autocrlf = false + eol = lf + pager = delta + +[interactive] + diffFilter = delta --color-only + +[delta] + navigate = true + dark = true + +[merge] + conflictstyle = diff3 + +[diff] + colorMoved = default + +[user] + name = Cody Duong + email = duongcody507@gmail.com + +[credential] + helper = C:/Users/duong/AppData/Local/Programs/Git\\ Credential\\ Manager/git-credential-manager.exe + +[credential "https://dev.azure.com"] + useHttpPath = true + +[credential "github.com"] + useHttpPath = true diff --git a/windows/aliases/yazi.ps1 b/windows/aliases/yazi.ps1 new file mode 100644 index 0000000..e44824b --- /dev/null +++ b/windows/aliases/yazi.ps1 @@ -0,0 +1,12 @@ +# https://yazi-rs.github.io/docs/quick-start +function yy +{ + $tmp = [System.IO.Path]::GetTempFileName() + yazi $args --cwd-file="$tmp" + $cwd = Get-Content -Path $tmp + if (-not [String]::IsNullOrEmpty($cwd) -and $cwd -ne $PWD.Path) + { + Set-Location -Path $cwd + } + Remove-Item -Path $tmp +} diff --git a/windows/exports.ps1 b/windows/exports.ps1 index eddc552..7bcf83f 100644 --- a/windows/exports.ps1 +++ b/windows/exports.ps1 @@ -28,13 +28,14 @@ $script:mingwPath = "C:\msys64\ucrt64\bin" Update-EnvPathIfNot (Join-Path -Path $Env:USERPROFILE -ChildPath '.pyenv\pyenv-win\bin') Update-EnvPathIfNot (Join-Path -Path $Env:USERPROFILE -ChildPath '.pyenv\pyenv-win\shims') Update-EnvPathIfNot (Join-Path -Path $env:APPDATA -ChildPath 'Python\Scripts') +# Update-EnvPathIfNot "C:\pkg-config-lite-0.28-1\bin" Update-EnvPathIfNot $msys2Path Update-EnvPathIfNot $mingwPath Update-EnvPathIfNot (Join-Path $env:LOCALAPPDATA "Programs\ILSpy") Update-EnvPathIfNot (Join-Path ([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFiles)) "PowerShell\7") Update-EnvPathIfNot (Join-Path $env:LOCALAPPDATA "Programs\oh-my-posh\bin") Update-EnvPathIfNot (Join-Path $env:ProgramFiles "\Neovim\bin") -Update-EnvPathIfNot "C:\Qt\6.6.1\msvc2019_64\bin" +# Update-EnvPathIfNot "C:\Qt\6.6.1\msvc2019_64\bin" # https://stackoverflow.com/a/57403956/17954209 -Update-EnvPathIfNot "C:\Qt\6.6.1\msvc2019_64\include" +# Update-EnvPathIfNot "C:\Qt\6.6.1\msvc2019_64\include" Update-EnvPathIfNot "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Scoop Apps" diff --git a/windows/scripts/install.ps1 b/windows/scripts/install.ps1 index ce5a910..81124bf 100644 --- a/windows/scripts/install.ps1 +++ b/windows/scripts/install.ps1 @@ -7,10 +7,11 @@ param ( . $PSScriptRoot\utils.ps1 . $PSScriptRoot\..\functions.ps1 -if ($update.IsPresent) { +if ($update.IsPresent) +{ $Env:UPDATE_OUTDATED_DEPS = $update -} -else { +} else +{ InstallerPromptUpdateOutdated } @@ -42,16 +43,21 @@ Install-Winget junegunn.fzf Install-Winget gerardog.gsudo Install-Winget ajeetdsouza.zoxide Install-Winget sharkdp.bat +Install-Winget dandavison.delta +# scoop install yazi +# scoop install unar jq poppler ### Install oh-my-posh and dependencies Install-Winget JanDeDobbeleer.OhMyPosh Install-PowerShell -Name Terminal-Icons -Repository PSGallery -Force -if ($true) { +if ($true) +{ $script:TerminalIconsForkPath = (Join-Path $env:USERPROFILE "Terminal-Icons") $script:TerminalIconsCloned = $false # Clone a fork of Terminal-Icons - if (-not (Test-Path -Path $TerminalIconsForkPath -PathType Container)) { + if (-not (Test-Path -Path $TerminalIconsForkPath -PathType Container)) + { Write-Host "Cloning Terminal-Icons (fork) v$TerminalIconsVersion..." -ForegroundColor $InstallationIndicatorColorInstalling git clone https://github.com/codyduong/Terminal-Icons.git "$TerminalIconsForkPath" $script:TerminalIconsCloned = $true @@ -60,17 +66,19 @@ if ($true) { # Pull if possible $script:gpOut = git -C "$TerminalIconsForkPath" pull - if ($gpOut -notlike '*Already up to date.*') { + if ($gpOut -notlike '*Already up to date.*') + { Write-Host "Pulling Terminal-Icons (fork)..." -ForegroundColor $InstallationIndicatorColorUpdating - } - else { + } else + { Write-Host "Terminal-Icons (fork) up to date." -ForegroundColor $InstallationIndicatorColorFound } # Install actual deps $script:manifestData = Import-PowerShellDataFile -Path (Join-Path $TerminalIconsForkPath "Terminal-Icons/Terminal-Icons.psd1") - foreach ($script:moduleName in $manifestData.RequiredModules) { + foreach ($script:moduleName in $manifestData.RequiredModules) + { Install-PowerShell -Name $moduleName -Force -RequiredVersion $moduleVersion } @@ -78,32 +86,38 @@ if ($true) { $script:manifestData2 = Import-PowerShellDataFile -Path (Join-Path $TerminalIconsForkPath "requirements.psd1") # Remove similiar deps - foreach ($script:actDep in $manifestData.Keys) { - if ($manifestData2.ContainsKey($actDep)) { + foreach ($script:actDep in $manifestData.Keys) + { + if ($manifestData2.ContainsKey($actDep)) + { $manifestData2.Remove($actDep) } } $script:psDependOptions = $manifestData2.PSDependOptions - $script:scope = if ($psDependOptions -and $psDependOptions.Target) { + $script:scope = if ($psDependOptions -and $psDependOptions.Target) + { $psDependOptions.Target - } - else { + } else + { 'CurrentUser' } - foreach ($script:moduleName in $manifestData2.Keys) { - if ($moduleName -eq 'PSDependOptions') { + foreach ($script:moduleName in $manifestData2.Keys) + { + if ($moduleName -eq 'PSDependOptions') + { continue } $script:moduleVersion = $manifestData2[$moduleName] - if ($moduleVersion -eq 'latest') { + if ($moduleVersion -eq 'latest') + { Install-PowerShell -Name $moduleName -Force -Scope $scope - } - else { + } else + { Install-PowerShell -Name $moduleName -Force -RequiredVersion $moduleVersion -Scope $scope } } @@ -111,26 +125,29 @@ if ($true) { $script:TerminalIconsVersion = (Import-PowerShellDataFile (Join-Path $TerminalIconsForkPath "Terminal-Icons/Terminal-Icons.psd1")).ModuleVersion # Build only if we haven't built the current version - if (-not (Test-Path -Path (Join-Path $TerminalIconsForkPath "Output/Terminal-Icons/$TerminalIconsVersion") -PathType Container)) { - if ($TerminalIconsCloned) { + if (-not (Test-Path -Path (Join-Path $TerminalIconsForkPath "Output/Terminal-Icons/$TerminalIconsVersion") -PathType Container)) + { + if ($TerminalIconsCloned) + { Write-Host "Building Terminal-Icons (fork) $TerminalIconsVersion..." -ForegroundColor $InstallationIndicatorColorInstalling - } - else { + } else + { Write-Host "Building Terminal-Icons (fork) $TerminalIconsVersion..." -ForegroundColor $InstallationIndicatorColorUpdating } Push-Location Set-Location $TerminalIconsForkPath & (Join-Path $TerminalIconsForkPath "build.ps1") Pop-Location - } - else { + } else + { Write-Host "Terminal-Icons (fork) $TerminalIconsVersion found, skipping build..." -ForegroundColor $InstallationIndicatorColorFound } } # Install Meslo if not already installed $script:fonts = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' -if (-not ($fonts.PSObject.Properties.name -contains 'Meslo LG S Bold Italic Nerd Font Complete Mono Windows Compatible (TrueType)')) { +if (-not ($fonts.PSObject.Properties.name -contains 'Meslo LG S Bold Italic Nerd Font Complete Mono Windows Compatible (TrueType)')) +{ Invoke-ElevatedScript { oh-my-posh font install Meslo } } @@ -145,11 +162,12 @@ Install-GitHubRelease ahk AutoHotkey/AutoHotkey ".*\.exe" # yasb $script:__yasb_repo = [System.IO.Path]::Combine("$HOME", 'yasb') -if (Test-Path $__yasb_repo) { +if (Test-Path $__yasb_repo) +{ Push-Location $__yasb_repo; git fetch && git pull; -} -else { +} else +{ git clone https://github.com/da-rth/yasb.git $__yasb_repo Push-Location $__yasb_repo } @@ -178,7 +196,8 @@ New-Item $PowerToysPluginsPath -ItemType Directory -Force -ErrorAction SilentlyC $script:EverythingPowerToysZip = $(Install-GitHubRelease lin-ycv/EverythingPowerToys lin-ycv/EverythingPowerToys ".*-x64\.zip$" -NoAction -Version $( (Get-Content -Path $(Join-Path $PowerToysPluginsPath "Everything\plugin.json") -Raw -ErrorAction SilentlyContinue | ConvertFrom-Json -ErrorAction SilentlyContinue).Version ?? "0.0.0" )) -if ($null -ne $EverythingPowerToysZip) { +if ($null -ne $EverythingPowerToysZip) +{ Expand-Archive -LiteralPath $EverythingPowerToysZip -DestinationPath $env:TEMP -Force Copy-Item -Path $(Join-Path $env:TEMP "Everything") -Destination $PowerToysPluginsPath -Recurse -Force } @@ -220,15 +239,17 @@ Write-Host "`nRust" -ForegroundColor "Cyan" ### Rust # See https://github.com/rust-lang/rustup/pull/3047, on occasion it will read Unknown, add a custom GetCurrent ScriptBlock Install-Winget Rustlang.Rustup -GetCurrent { - try { - if ((Get-Command rustup -ErrorAction SilentlyContinue) -and ($(rustup --version) -match "(?<=rustup)\s*[\d\.]+")) { + try + { + if ((Get-Command rustup -ErrorAction SilentlyContinue) -and ($(rustup --version) -match "(?<=rustup)\s*[\d\.]+")) + { [version]($matches[0]) - } - else { + } else + { [version]"0.0.0" } - } - catch { + } catch + { Write-Warning $_ [version]"0.0.0" } @@ -237,20 +258,34 @@ Install-Winget Rustlang.Rustup -GetCurrent { Write-Host "`nC/C++" -ForegroundColor "Cyan" $script:msys2Path = "C:\msys64\usr\bin" $script:mingwPath = "C:\msys64\ucrt64\bin" + +# https://github.com/rust-lang/pkg-config-rs/issues/51#issuecomment-346300858 +# WTF bruh -@codyduong + # This has an superfluous call but idgaf. We really only care when the gcc version is updated, so use that as our baseline lib for when to upgrade $script:msys2Remote = Invoke-RestMethod https://api.github.com/repos/msys2/msys2-installer/releases/latest $script:msys2PackagesAsset = $msys2Remote.assets | Where-Object { $_.name -match "msys2-base-x86_64-latest.packages.txt" } $script:msys2PackagesTxt = Join-Path $env:TEMP "Github" $msys2PackagesAsset.name Invoke-WebRequest -Uri $msys2PackagesAsset.browser_download_url -OutFile $msys2PackagesTxt -$script:msys2RemoteVersion = if (Get-Content -Path $msys2PackagesTxt | Where-Object { $_ -match "(?<=gcc-libs )(\d+\.\d+\.\d+)" }) { $matches[0] } else { "0.0.0" } +$script:msys2RemoteVersion = if (Get-Content -Path $msys2PackagesTxt | Where-Object { $_ -match "(?<=gcc-libs )(\d+\.\d+\.\d+)" }) +{ $matches[0] +} else +{ "0.0.0" +} $script:msys2LocalVersion = "0.0.0" -try { +try +{ $script:msys2LocalVersion = if ( # We use head instead of cat because there is some fuckery going on with Neovim/bin/cat.exe being on PATH that sometimes blows up msys2 bash cat $(& $msys2Path\bash.exe -c "head /proc/version") -match "(?<=gcc version )\d+\.\d+\.\d+" - ) { $matches[0] } else { "0.0.0" } + ) + { $matches[0] + } else + { "0.0.0" + } +} catch +{ Write-Warning $_ } -catch { Write-Warning $_ } Install-GitHubRelease msys2 msys2/msys2-installer "msys2-x86_64-latest\.exe$" -version $msys2LocalVersion -remoteVersion $msys2RemoteVersion # install mingw @@ -287,7 +322,8 @@ Install-Winget OBSProject.OBSStudio ### PATCH W11 # https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information -if (([Environment]::OSVersion.Version).Build -ge 22621) { +if (([Environment]::OSVersion.Version).Build -ge 22621) +{ Install-Winget valinet.ExplorerPatcher } @@ -298,10 +334,11 @@ Clear-PowershellAll # WSL ##### Write-Host "`nInstalling WSL" -ForegroundColor "Yellow" -try { +try +{ wsl -v -} -catch { +} catch +{ wsl --install } @@ -314,6 +351,7 @@ reboot Windows for WSL to work properly "@ -ForegroundColor White Write-Host " * Reloading shell automatically..." -ForegroundColor Cyan Write-Host "=======================================`n" -ForegroundColor White -if (-not $update) { +if (-not $update) +{ Invoke-Command { & "pwsh.exe" -NoLogo } -NoNewScope }