public
imalexnord
read
ms.open
Adds Mac "Open ." command to Windows
Languages
Repository composition by tracked source files.
PowerShell
100%
Create file
Wiki Documentation
Clone
https://nobgit.com/user/imalexnord/ms.open.git
ssh://[email protected]:2222/user/imalexnord/ms.open.git
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$root = $PSScriptRoot
$binPath = Join-Path $root 'bin'
function Normalize-PathEntry {
param([string]$Value)
if ([string]::IsNullOrWhiteSpace($Value)) {
return ''
}
return $Value.Trim().TrimEnd('\')
}
function Remove-UserPath {
param([string]$PathToRemove)
$current = [Environment]::GetEnvironmentVariable('Path', 'User')
$normalizedTarget = Normalize-PathEntry $PathToRemove
$entries = @(
$current -split ';' |
ForEach-Object { Normalize-PathEntry $_ } |
Where-Object {
$_ -and -not $_.Equals($normalizedTarget, [StringComparison]::OrdinalIgnoreCase)
}
)
[Environment]::SetEnvironmentVariable('Path', ($entries -join ';'), 'User')
Write-Host "Removed from user PATH: $PathToRemove"
}
function Remove-ProfileBlock {
param([string]$ProfilePath)
if (-not (Test-Path -LiteralPath $ProfilePath)) {
return
}
$beginMarker = '# >>> MS.Open >>>'
$endMarker = '# <<< MS.Open <<<'
$content = Get-Content -LiteralPath $ProfilePath -Raw
$pattern = "(?ms)^$([regex]::Escape($beginMarker)).*?^$([regex]::Escape($endMarker))\s*"
$cleaned = [regex]::Replace($content, $pattern, '').TrimEnd()
if ($cleaned) {
Set-Content -LiteralPath $ProfilePath -Value "$cleaned`r`n" -Encoding UTF8
}
else {
Set-Content -LiteralPath $ProfilePath -Value '' -Encoding UTF8
}
Write-Host "Removed MS.Open from profile: $ProfilePath"
}
Remove-UserPath -PathToRemove $binPath
$documents = [Environment]::GetFolderPath('MyDocuments')
$profiles = @(
(Join-Path $documents 'WindowsPowerShell\Microsoft.PowerShell_profile.ps1'),
(Join-Path $documents 'PowerShell\Microsoft.PowerShell_profile.ps1')
) | Select-Object -Unique
foreach ($profilePath in $profiles) {
Remove-ProfileBlock -ProfilePath $profilePath
}
Write-Host ''
Write-Host 'MS.Open has been uninstalled from PATH and PowerShell profiles.'
Write-Host 'Restart your terminal. You can then delete this folder.'