-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-RoboSyPath.ps1
More file actions
75 lines (64 loc) · 2.31 KB
/
Copy pathInstall-RoboSyPath.ps1
File metadata and controls
75 lines (64 loc) · 2.31 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# SPDX-License-Identifier: MIT
# Copyright (c) 2026 Kiaro Sama
$ErrorActionPreference = "Stop"
$projectDir = Split-Path -Parent $PSCommandPath
$shimDir = Join-Path -Path $env:USERPROFILE -ChildPath ".dotnet\tools"
$shimPath = Join-Path -Path $shimDir -ChildPath "RoboSy.cmd"
$currentUserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ([string]::IsNullOrWhiteSpace($currentUserPath)) {
$entries = @()
}
else {
$entries = @($currentUserPath -split ";" | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
}
$alreadyInstalled = $false
foreach ($entry in $entries) {
if ([string]::Equals($entry.TrimEnd('\'), $projectDir.TrimEnd('\'), [StringComparison]::OrdinalIgnoreCase)) {
$alreadyInstalled = $true
break
}
}
[System.IO.Directory]::CreateDirectory($shimDir) | Out-Null
$shimLines = @(
"@echo off",
"setlocal",
"set ""ROBOSY_TARGET=$projectDir\RoboSy.cmd""",
"if not exist ""%ROBOSY_TARGET%"" (",
" echo RoboSy target was not found: %ROBOSY_TARGET%",
" exit /b 1",
")",
"call ""%ROBOSY_TARGET%"" %*",
"exit /b %errorlevel%"
)
try {
Set-Content -LiteralPath $shimPath -Value $shimLines -Encoding OEM -ErrorAction Stop
}
catch {
Set-Content -LiteralPath $shimPath -Value $shimLines -Encoding Default -ErrorAction Stop
}
Write-Host "Installed command shim:" -ForegroundColor Green
Write-Host " $shimPath" -ForegroundColor Cyan
$shimDirInPath = $false
foreach ($entry in $entries) {
if ([string]::Equals($entry.TrimEnd('\'), $shimDir.TrimEnd('\'), [StringComparison]::OrdinalIgnoreCase)) {
$shimDirInPath = $true
break
}
}
if (-not $alreadyInstalled -or -not $shimDirInPath) {
if (-not $alreadyInstalled) {
$entries += $projectDir
}
if (-not $shimDirInPath) {
$entries += $shimDir
}
$newPath = ($entries | Select-Object -Unique) -join ";"
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Host "Updated the current user's PATH." -ForegroundColor Green
}
else {
Write-Host "RoboSy project folder and shim folder are already in the current user's PATH." -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Run this in a new terminal, or in the current terminal if .dotnet tools was already on PATH:" -ForegroundColor Gray
Write-Host " RoboSy" -ForegroundColor Cyan