-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
59 lines (47 loc) · 1.5 KB
/
install.ps1
File metadata and controls
59 lines (47 loc) · 1.5 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
$ErrorActionPreference = "Stop"
gcc .\main.c -o .\petch.exe
$targetDir = "$env:LOCALAPPDATA\petch\bin"
if (-not (Test-Path $targetDir)) {
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
}
Copy-Item .\petch.exe "$targetDir\petch.exe" -Force
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not $userPath) {
$userPath = ""
}
$pathEntries = $userPath -split ";" | Where-Object { $_ -ne "" }
if ($pathEntries -notcontains $targetDir) {
$newPath = if ($userPath.Trim() -eq "") {
$targetDir
} else {
"$userPath;$targetDir"
}
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
$env:Path = "$env:Path;$targetDir"
Write-Host "Added to user PATH: $targetDir"
}
$profilePath = $PROFILE
$profileDir = Split-Path $profilePath -Parent
if (-not (Test-Path $profileDir)) {
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
}
if (-not (Test-Path $profilePath)) {
New-Item -ItemType File -Path $profilePath -Force | Out-Null
}
$block = @'
# >>> petch auto-start >>>
if (Get-Command petch -ErrorAction SilentlyContinue) {
if ((Get-Random -Minimum 0 -Maximum 6) -eq 0) {
Write-Host ""
petch poke
Write-Host ""
}
}
# <<< petch auto-start <<<
'@
$content = Get-Content $profilePath -Raw
if ($content -notmatch "petch auto-start") {
Add-Content -Path $profilePath -Value $block
Write-Host "Updated PowerShell profile: $profilePath"
}
Write-Host "Petch installed. Restart PowerShell."