-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptsd.ps1
More file actions
69 lines (56 loc) · 2.29 KB
/
ptsd.ps1
File metadata and controls
69 lines (56 loc) · 2.29 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
# ptsd - Project Terminal Switch Directory (PowerShell)
# Lists recent Claude project directories and navigates to the selected one.
#
# Installation: add the following to your PowerShell profile ($PROFILE):
# . "C:\path\to\ptsd\ptsd.ps1"
#
# Then run: ptsd
function ptsd {
$projectsDir = "$env:USERPROFILE\.claude\projects"
if (-not (Test-Path $projectsDir)) {
Write-Host "No Claude projects directory found at $projectsDir"
return
}
$cwds = [System.Collections.Generic.List[string]]::new()
$seen = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
# Get project dirs sorted by most recently modified (newest first)
$projectDirs = Get-ChildItem -Path $projectsDir -Directory |
Sort-Object LastWriteTime -Descending
foreach ($projectDir in $projectDirs) {
# Find the newest JSONL file in this project dir
$newestJsonl = Get-ChildItem -Path $projectDir.FullName -Filter '*.jsonl' -ErrorAction SilentlyContinue |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if (-not $newestJsonl) { continue }
# Find the first line containing a cwd field and parse it
$cwd = $null
foreach ($line in [System.IO.File]::ReadLines($newestJsonl.FullName)) {
if ($line -notmatch '"cwd"') { continue }
try {
$cwd = ($line | ConvertFrom-Json).cwd
break
} catch { continue }
}
if (-not $cwd) { continue }
if (-not (Test-Path $cwd)) { continue }
if (-not $seen.Add($cwd)) { continue } # Add returns false if already present
$cwds.Add($cwd)
}
if ($cwds.Count -eq 0) {
Write-Host 'No Claude project directories found.'
return
}
Write-Host ''
for ($i = 0; $i -lt $cwds.Count; $i++) {
Write-Host (' {0,2}) {1}' -f ($i + 1), $cwds[$i])
}
Write-Host ''
$selection = Read-Host "Select project (1-$($cwds.Count))"
if ($selection -match '^\d+$' -and [int]$selection -ge 1 -and [int]$selection -le $cwds.Count) {
$target = $cwds[[int]$selection - 1]
Write-Host "→ $target"
Set-Location $target
} else {
Write-Host 'Invalid selection'
}
}