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
Trace
uninstall.ps1
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
[CmdletBinding()]
2
param()
4
Set-StrictMode -Version Latest
5
$ErrorActionPreference = 'Stop'
7
$root = $PSScriptRoot
8
$binPath = Join-Path $root 'bin'
10
function Normalize-PathEntry {
11
param([string]$Value)
13
if ([string]::IsNullOrWhiteSpace($Value)) {
14
return ''
15
}
17
return $Value.Trim().TrimEnd('\')
18
}
20
function Remove-UserPath {
21
param([string]$PathToRemove)
23
$current = [Environment]::GetEnvironmentVariable('Path', 'User')
24
$normalizedTarget = Normalize-PathEntry $PathToRemove
26
$entries = @(
27
$current -split ';' |
28
ForEach-Object { Normalize-PathEntry $_ } |
29
Where-Object {
30
$_ -and -not $_.Equals($normalizedTarget, [StringComparison]::OrdinalIgnoreCase)
31
}
32
)
34
[Environment]::SetEnvironmentVariable('Path', ($entries -join ';'), 'User')
35
Write-Host "Removed from user PATH: $PathToRemove"
36
}
38
function Remove-ProfileBlock {
39
param([string]$ProfilePath)
41
if (-not (Test-Path -LiteralPath $ProfilePath)) {
42
return
43
}
45
$beginMarker = '# >>> MS.Open >>>'
46
$endMarker = '# <<< MS.Open <<<'
47
$content = Get-Content -LiteralPath $ProfilePath -Raw
48
$pattern = "(?ms)^$([regex]::Escape($beginMarker)).*?^$([regex]::Escape($endMarker))\s*"
49
$cleaned = [regex]::Replace($content, $pattern, '').TrimEnd()
51
if ($cleaned) {
52
Set-Content -LiteralPath $ProfilePath -Value "$cleaned`r`n" -Encoding UTF8
53
}
54
else {
55
Set-Content -LiteralPath $ProfilePath -Value '' -Encoding UTF8
56
}
58
Write-Host "Removed MS.Open from profile: $ProfilePath"
59
}
61
Remove-UserPath -PathToRemove $binPath
63
$documents = [Environment]::GetFolderPath('MyDocuments')
64
$profiles = @(
65
(Join-Path $documents 'WindowsPowerShell\Microsoft.PowerShell_profile.ps1'),
66
(Join-Path $documents 'PowerShell\Microsoft.PowerShell_profile.ps1')
67
) | Select-Object -Unique
69
foreach ($profilePath in $profiles) {
70
Remove-ProfileBlock -ProfilePath $profilePath
71
}
73
Write-Host ''
74
Write-Host 'MS.Open has been uninstalled from PATH and PowerShell profiles.'
75
Write-Host 'Restart your terminal. You can then delete this folder.'