summaryrefslogtreecommitdiff
path: root/scripts/dev/hide_ignored_file.ps1
blob: 0ab2632810806341ca03c0a3f5240237af30c917 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Check `last_check`

$lastCheckFile = Join-Path $PSScriptRoot "last_check"
$currentTime = Get-Date
$timeThreshold = 10

if (Test-Path $lastCheckFile) {
    $lastCheckTime = Get-Content $lastCheckFile | Get-Date
    $timeDiff = ($currentTime - $lastCheckTime).TotalMinutes

    if ($timeDiff -lt $timeThreshold) {
        exit
    }
}

$currentTime.ToString() | Out-File -FilePath $lastCheckFile -Force

# Hide Files

Set-Location -Path (Join-Path $PSScriptRoot "..\..")

Get-ChildItem -Path . -Force -Recurse -ErrorAction SilentlyContinue | Where-Object {
    $_.FullName -notmatch '\\.temp\\' -and $_.FullName -notmatch '\\.git\\'
} | ForEach-Object {
    attrib -h $_.FullName 2>&1 | Out-Null
}

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
}

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
            }
        }
    }
}