diff --git a/install-tmux.ps1 b/install-tmux.ps1 index 39d0f94..e7a977c 100644 --- a/install-tmux.ps1 +++ b/install-tmux.ps1 @@ -63,21 +63,70 @@ if ($tmuxCmd) { Success "tmux installed via winget" } -# Verify tmux is available (may need PATH refresh) +# ──────────────────────────────────────────── +# Verify tmux is available and add to PATH permanently if needed +# ──────────────────────────────────────────── +$tmuxBin = $null + +# 1) Try current PATH $tmuxCmd = Get-Command tmux -ErrorAction SilentlyContinue if ($tmuxCmd) { - Success "tmux is available: $($tmuxCmd.Source)" -} else { - # Refresh PATH for current session + $tmuxBin = $tmuxCmd.Source +} + +# 2) Refresh PATH from registry (winget may have added paths) +if (-not $tmuxBin) { $env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'User') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'Machine') $tmuxCmd = Get-Command tmux -ErrorAction SilentlyContinue if ($tmuxCmd) { - Success "tmux is available: $($tmuxCmd.Source)" - } else { - Warn "tmux was not found in PATH after installation. You may need to restart your terminal." + $tmuxBin = $tmuxCmd.Source } } +# 3) Search common locations where winget installs tmux-windows +if (-not $tmuxBin) { + $searchDirs = @( + (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links'), + (Join-Path $env:LOCALAPPDATA 'Programs\tmux-windows'), + 'C:\Program Files\tmux-windows', + 'C:\Program Files (x86)\tmux-windows' + ) + foreach ($dir in $searchDirs) { + if (Test-Path $dir) { + $candidate = Join-Path $dir 'tmux.exe' + if (Test-Path $candidate) { $tmuxBin = $candidate; break } + } + } + + # Recurse under WinGet/Packages for tmux + if (-not $tmuxBin -and (Test-Path (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Packages'))) { + $found = Get-ChildItem -Path (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Packages') -Recurse -Filter 'tmux.exe' -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($found) { $tmuxBin = $found.FullName } + } +} + +if ($tmuxBin) { + # Add tmux's directory to PATH for this session + $tmuxDir = Split-Path $tmuxBin + if ($env:Path -notlike "*$tmuxDir*") { + $env:Path = "$tmuxDir;$env:Path" + Info "Added $tmuxDir to PATH for this session" + } + Success "tmux is available: $tmuxBin" + + # Permanently add tmux's directory to user PATH if not already there + $userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User') + if ($userPath -notlike "*$tmuxDir*") { + [System.Environment]::SetEnvironmentVariable('Path', "$tmuxDir;$userPath", 'User') + Success "Added $tmuxDir to user PATH permanently (takes effect on next login)" + } else { + Info "$tmuxDir already in user PATH" + } +} else { + Warn "tmux was not found in PATH after installation." + Warn "Please restart your terminal or add tmux's directory to your PATH manually." +} + # ──────────────────────────────────────────── # Step 2: Deploy .tmux.conf # ──────────────────────────────────────────── @@ -178,6 +227,10 @@ Info "" Info "==================================================" Success "tmux installation complete!" Info "==================================================" +if ($tmuxBin) { + Info "" + Info "tmux binary: $tmuxBin" +} Info "" Info "Getting started:" Info " tmux - Start a new session"