Skip to content

Instantly share code, notes, and snippets.

@instance-id
Last active April 13, 2021 03:16
Show Gist options
  • Save instance-id/7817ac88810319fc72ac8f4eb942ebd2 to your computer and use it in GitHub Desktop.
Save instance-id/7817ac88810319fc72ac8f4eb942ebd2 to your computer and use it in GitHub Desktop.
Search for and remove all directories that match a string from git tracking (Powershell on Linux host)
[CmdletBinding()]
param (
[Parameter()][String]$path = $HOME
)
$jobs = @()
$directories = @()
try {
Import-Module PoshRSJob
foreach ($directory in [System.IO.Directory]::EnumerateDirectories($path, '*.*' , 'TopDirectoryOnly')) {
try { $folderObject = Get-Item $directory -ErrorAction SilentlyContinue } catch [UnauthorizedAccessException] {}
$directories += $directory
Write-Host $directory
}
$jobs = $directories | Start-RSJob -ArgumentList $_ {
param($directory)
try {
$results = $directory | gci -Recurse -Force | Where-Object { $_.PSIsContainer -and $_.name -eq '.history' } | Select-Object -expandproperty Parent
$actualResults = $results | % {
Set-Location $_.FullName
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME rm -r --cached **/.history*
echo $_.FullName
}
$actualResults
} catch { [Console]::WriteLine("${_}") }
}
$jobs | Wait-RsJob -ShowProgress | receive-rsjob > "$HOME/script_output.txt"
} catch { Write-Host "${_}" -f red }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment