|
1 | 1 | # TimeTree installation script for Windows PowerShell |
2 | 2 | # This script builds and installs timetree and tt commands |
3 | 3 |
|
4 | | -$ErrorActionPreference = "Stop" |
| 4 | +$ErrorActionPreference = 'Stop' |
5 | 5 |
|
6 | 6 | # Get script directory and project root |
7 | | -$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 7 | +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
8 | 8 | $ProjectRoot = Split-Path -Parent $ScriptDir |
9 | 9 |
|
10 | 10 | # Change to project root |
11 | 11 | Set-Location $ProjectRoot |
12 | 12 |
|
13 | | -Write-Host "Building TimeTree..." -ForegroundColor Green |
| 13 | +Write-Host 'Building TimeTree...' -ForegroundColor Green |
14 | 14 | & .\gradlew.bat shadowJar --no-daemon |
15 | 15 | if ($LASTEXITCODE -ne 0) { |
16 | | - Write-Host "Error: Failed to build TimeTree" -ForegroundColor Red |
| 16 | + Write-Host 'Error: Failed to build TimeTree' -ForegroundColor Red |
17 | 17 | exit 1 |
18 | 18 | } |
19 | 19 |
|
20 | | -$JarFile = Join-Path $ProjectRoot "build\libs\timetree.jar" |
| 20 | +$JarFile = Join-Path $ProjectRoot 'build\libs\timetree.jar' |
21 | 21 |
|
22 | 22 | # Check if JAR exists |
23 | 23 | if (-not (Test-Path $JarFile)) { |
24 | | - Write-Host "Error: timetree.jar not found at $JarFile" -ForegroundColor Red |
| 24 | + Write-Host ('Error: timetree.jar not found at ' + $JarFile) -ForegroundColor Red |
25 | 25 | exit 1 |
26 | 26 | } |
27 | 27 |
|
28 | 28 | # Determine installation directory |
29 | | -$InstallDir = Join-Path $env:LOCALAPPDATA "TimeTree\bin" |
| 29 | +$InstallDir = Join-Path $env:LOCALAPPDATA 'TimeTree\bin' |
30 | 30 | if (-not (Test-Path $InstallDir)) { |
31 | 31 | New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null |
32 | 32 | } |
33 | 33 |
|
34 | | -Write-Host "Installing timetree to $InstallDir..." -ForegroundColor Green |
| 34 | +Write-Host ('Installing timetree to ' + $InstallDir + '...') -ForegroundColor Green |
35 | 35 |
|
36 | 36 | # Create wrapper batch file for timetree |
37 | | -$TimetreeBat = @' |
38 | | -@echo off |
39 | | -REM TimeTree wrapper script |
40 | | -set "JAR_FILE=%~dp0timetree.jar" |
41 | | -java -jar "%JAR_FILE%" %* |
42 | | -'@ |
43 | | -$TimetreeBat | Out-File -FilePath (Join-Path $InstallDir "timetree.bat") -Encoding ASCII |
| 37 | +$TimetreeBatLines = @( |
| 38 | + '@echo off' |
| 39 | + 'REM TimeTree wrapper script' |
| 40 | + 'set "JAR_FILE=%~dp0timetree.jar"' |
| 41 | + 'java -jar "%JAR_FILE%" %*' |
| 42 | +) |
| 43 | +$TimetreeBat = $TimetreeBatLines -join "`r`n" |
| 44 | +$TimetreeBat | Out-File -FilePath (Join-Path $InstallDir 'timetree.bat') -Encoding ASCII -NoNewline |
44 | 45 |
|
45 | 46 | # Copy the JAR file |
46 | | -Copy-Item $JarFile (Join-Path $InstallDir "timetree.jar") -Force |
| 47 | +Copy-Item $JarFile (Join-Path $InstallDir 'timetree.jar') -Force |
47 | 48 |
|
48 | 49 | # Create tt.bat wrapper |
49 | | -$TtBat = @' |
50 | | -@echo off |
51 | | -REM TimeTree 'tt' wrapper script |
52 | | -set "JAR_FILE=%~dp0timetree.jar" |
53 | | -java -jar "%JAR_FILE%" %* |
54 | | -'@ |
55 | | -$TtBat | Out-File -FilePath (Join-Path $InstallDir "tt.bat") -Encoding ASCII |
| 50 | +$TtBatLines = @( |
| 51 | + '@echo off' |
| 52 | + 'REM TimeTree ''tt'' wrapper script' |
| 53 | + 'set "JAR_FILE=%~dp0timetree.jar"' |
| 54 | + 'java -jar "%JAR_FILE%" %*' |
| 55 | +) |
| 56 | +$TtBat = $TtBatLines -join "`r`n" |
| 57 | +$TtBat | Out-File -FilePath (Join-Path $InstallDir 'tt.bat') -Encoding ASCII -NoNewline |
56 | 58 |
|
57 | | -Write-Host "✓ Successfully installed timetree and tt to $InstallDir" -ForegroundColor Green |
| 59 | +Write-Host ('✓ Successfully installed timetree and tt to ' + $InstallDir) -ForegroundColor Green |
58 | 60 |
|
59 | 61 | # Check if directory is in PATH |
60 | | -$CurrentPath = [Environment]::GetEnvironmentVariable("Path", "User") |
61 | | -if ($CurrentPath -notlike "*$InstallDir*") { |
62 | | - Write-Host "" |
63 | | - Write-Host "Warning: $InstallDir is not in your PATH" -ForegroundColor Yellow |
64 | | - Write-Host "Add this directory to your PATH:" -ForegroundColor Yellow |
| 62 | +$CurrentPath = [Environment]::GetEnvironmentVariable('Path', 'User') |
| 63 | +if ($CurrentPath -notlike ('*' + $InstallDir + '*')) { |
| 64 | + Write-Host '' |
| 65 | + Write-Host ('Warning: ' + $InstallDir + ' is not in your PATH') -ForegroundColor Yellow |
| 66 | + Write-Host 'Add this directory to your PATH:' -ForegroundColor Yellow |
65 | 67 | Write-Host " 1. Press Win+R, type 'sysdm.cpl' and press Enter" -ForegroundColor Yellow |
66 | 68 | Write-Host " 2. Go to 'Advanced' tab, click 'Environment Variables'" -ForegroundColor Yellow |
67 | 69 | Write-Host " 3. Under 'User variables', select 'Path' and click 'Edit'" -ForegroundColor Yellow |
68 | | - Write-Host " 4. Click 'New' and add: $InstallDir" -ForegroundColor Yellow |
69 | | - Write-Host " 5. Click OK on all dialogs" -ForegroundColor Yellow |
70 | | - Write-Host "" |
71 | | - Write-Host "Or add to PATH with this PowerShell command:" -ForegroundColor Yellow |
| 70 | + Write-Host (' 4. Click ''New'' and add: ' + $InstallDir) -ForegroundColor Yellow |
| 71 | + Write-Host ' 5. Click OK on all dialogs' -ForegroundColor Yellow |
| 72 | + Write-Host '' |
| 73 | + Write-Host 'Or add to PATH with this PowerShell command:' -ForegroundColor Yellow |
72 | 74 |
|
73 | | - $PathCommand = "[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path','User') + ';$InstallDir', 'User')" |
74 | | - Write-Host " $PathCommand" -ForegroundColor Green |
| 75 | + # Build a literal command string with doubled single-quotes for embedding |
| 76 | + $PathCommand = ( |
| 77 | + '[Environment]::SetEnvironmentVariable(''Path'', ' + |
| 78 | + '[Environment]::GetEnvironmentVariable(''Path'',''User'') + '';' + |
| 79 | + $InstallDir + |
| 80 | + ''', ''User'')' |
| 81 | + ) |
| 82 | + |
| 83 | + Write-Host (' ' + $PathCommand) -ForegroundColor Green |
75 | 84 | } else { |
76 | | - Write-Host "+ $InstallDir is already in your PATH" -ForegroundColor Green |
| 85 | + Write-Host ('+ ' + $InstallDir + ' is already in your PATH') -ForegroundColor Green |
77 | 86 | } |
78 | 87 |
|
79 | | -Write-Host "" |
80 | | -Write-Host "Installation complete! You can now use 'timetree' and 'tt' commands." -ForegroundColor Green |
81 | | -Write-Host "Note: You may need to restart your terminal for PATH changes to take effect." -ForegroundColor Yellow |
| 88 | +Write-Host '' |
| 89 | +Write-Host 'Installation complete! You can now use ''timetree'' and ''tt'' commands.' -ForegroundColor Green |
| 90 | +Write-Host 'Note: You may need to restart your terminal for PATH changes to take effect.' -ForegroundColor Yellow |
0 commit comments