aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.run/.gitignore2
-rw-r--r--.run/src/bin/windows-folder-hide.ps1126
2 files changed, 99 insertions, 29 deletions
diff --git a/.run/.gitignore b/.run/.gitignore
index 0dc39b0..40f407e 100644
--- a/.run/.gitignore
+++ b/.run/.gitignore
@@ -3,5 +3,3 @@
# If you want to add some Rust crates? Remove this line
# /Cargo.*
-
-last_check
diff --git a/.run/src/bin/windows-folder-hide.ps1 b/.run/src/bin/windows-folder-hide.ps1
index 0ab2632..ff53202 100644
--- a/.run/src/bin/windows-folder-hide.ps1
+++ b/.run/src/bin/windows-folder-hide.ps1
@@ -1,43 +1,115 @@
-# Check `last_check`
+$skipDirs = @('.git', '.temp', 'target', 'node_modules', '.pnpm')
+$selfPath = (Get-Item -LiteralPath $MyInvocation.MyCommand.Path).Directory.FullName
-$lastCheckFile = Join-Path $PSScriptRoot "last_check"
-$currentTime = Get-Date
-$timeThreshold = 10
+function Test-InSkipDir {
+ param(
+ [object]$Item
+ )
+ $path = if ($Item -is [string]) {
+ $Item
+ } elseif ($Item.PSPath) {
+ $Item.PSPath -replace '^.*::', ''
+ } else {
+ $Item.FullName
+ }
+
+ $parts = $path.Split([System.IO.Path]::DirectorySeparatorChar)
+ for ($i = 0; $i -lt $parts.Length - 1; $i++) {
+ if ($parts[$i] -in $skipDirs) {
+ return $true
+ }
+ }
+ return $false
+}
-if (Test-Path $lastCheckFile) {
- $lastCheckTime = Get-Content $lastCheckFile | Get-Date
- $timeDiff = ($currentTime - $lastCheckTime).TotalMinutes
+function Invoke-UnhideRecursive {
+ param([string]$Path)
+ Get-ChildItem -LiteralPath $Path -Force | ForEach-Object {
+ if ($_.PSIsContainer) {
+ if ($_.Name -in $skipDirs) {
+ if ($_.Attributes -band [System.IO.FileAttributes]::Hidden) {
+ Write-Host " -> unhiding skip directory (self only): `"$($_.FullName)`""
+ $_.Attributes = $_.Attributes -bxor [System.IO.FileAttributes]::Hidden
+ }
+ return
+ }
+ Invoke-UnhideRecursive $_.FullName
+ } else {
+ if ($_.Attributes -band [System.IO.FileAttributes]::Hidden) {
+ Write-Host " -> unhiding: `"$($_.FullName)`""
+ $_.Attributes = $_.Attributes -bxor [System.IO.FileAttributes]::Hidden
+ }
+ }
+ }
+}
- if ($timeDiff -lt $timeThreshold) {
- exit
+function Test-GitPathSkippable {
+ param([string]$GitPath)
+ $parts = $GitPath.Split(@('/', '\'))
+ for ($i = 0; $i -lt $parts.Length - 1; $i++) {
+ if ($parts[$i] -in $skipDirs) {
+ return $true
+ }
}
+ return $false
}
-$currentTime.ToString() | Out-File -FilePath $lastCheckFile -Force
+Write-Host "Step 1: Unhiding all files and directories (skipping $($skipDirs -join ', '))..."
-# Hide Files
+Invoke-UnhideRecursive -Path (Get-Location).Path
-Set-Location -Path (Join-Path $PSScriptRoot "..\..")
+Write-Host "Step 2: Hiding git-ignored items..."
-Get-ChildItem -Path . -Force -Recurse -ErrorAction SilentlyContinue | Where-Object {
- $_.FullName -notmatch '\\.temp\\' -and $_.FullName -notmatch '\\.git\\'
+git ls-files --others --ignored --exclude-standard | Where-Object {
+ -not (Test-GitPathSkippable $_)
} | ForEach-Object {
- attrib -h $_.FullName 2>&1 | Out-Null
+ $itemPath = $_
+ Write-Host "... checking: `"$itemPath`""
+ $item = Get-Item $_ -Force -ErrorAction SilentlyContinue
+ if (-not $item) { return }
+
+ if ($item.FullName -eq $selfPath) { return }
+
+ if (Test-InSkipDir $item) {
+ Write-Host " -> skipping (inside skip directory)"
+ return
+ }
+
+ if ($item.PSIsContainer) {
+ if (-not ($item.Attributes -band [System.IO.FileAttributes]::Hidden)) {
+ Write-Host " -> hiding directory (non-recursive)"
+ $item.Attributes = $item.Attributes -bor [System.IO.FileAttributes]::Hidden
+ }
+ } else {
+ if (-not ($item.Attributes -band [System.IO.FileAttributes]::Hidden)) {
+ Write-Host " -> hiding"
+ $item.Attributes = $item.Attributes -bor [System.IO.FileAttributes]::Hidden
+ }
+ }
}
-Get-ChildItem -Path . -Force -Recurse -ErrorAction SilentlyContinue | Where-Object {
- $_.Name -match '^\..*' -and $_.FullName -notmatch '\\\.\.$' -and $_.FullName -notmatch '\\\.$'
-} | ForEach-Object {
- attrib +h $_.FullName 2>&1 | Out-Null
+Write-Host "Step 3: Hiding dot-prefixed items..."
+Get-ChildItem -Path . -Force -Directory | Where-Object { $_.Name -match '^\.' } | ForEach-Object {
+ Write-Host "... checking: `"$($_.FullName)`""
+ if (Test-InSkipDir $_) {
+ Write-Host " -> skipping (inside skip directory)"
+ return
+ }
+ if (-not ($_.Attributes -band [System.IO.FileAttributes]::Hidden)) {
+ Write-Host " -> hiding directory"
+ $_.Attributes = $_.Attributes -bor [System.IO.FileAttributes]::Hidden
+ }
}
-if (Get-Command git -ErrorAction SilentlyContinue) {
- git status --ignored --short | ForEach-Object {
- if ($_ -match '^!!\s+(.+)$') {
- $ignoredPath = $matches[1]
- if ($ignoredPath -notmatch '\.lnk$' -and (Test-Path $ignoredPath)) {
- attrib +h $ignoredPath 2>&1 | Out-Null
- }
- }
+Get-ChildItem -Path . -Force -File | Where-Object { $_.Name -match '^\.' } | ForEach-Object {
+ if ($_.FullName -eq $selfPath) { return }
+ Write-Host "... checking: `"$($_.FullName)`""
+ if (Test-InSkipDir $_) {
+ Write-Host " -> skipping (inside skip directory)"
+ return
+ }
+ if (-not ($_.Attributes -band [System.IO.FileAttributes]::Hidden)) {
+ Write-Host " -> hiding file"
+ $_.Attributes = $_.Attributes -bor [System.IO.FileAttributes]::Hidden
}
}