|
| 1 | +use std::io::Write; |
| 2 | +use std::process::Command; |
| 3 | +use std::process::Stdio; |
| 4 | + |
| 5 | +use anyhow::Context; |
| 6 | +use anyhow::Result; |
| 7 | + |
| 8 | +fn main() -> Result<()> { |
| 9 | + // Kill any existing session |
| 10 | + let _ = Command::new("tmux") |
| 11 | + .args(["kill-session", "-t", "djls-debug"]) |
| 12 | + .output(); |
| 13 | + |
| 14 | + let _ = Command::new("pkill").args(["-f", "lsp-devtools"]).output(); |
| 15 | + |
| 16 | + // Start tmux in control mode |
| 17 | + let mut tmux = Command::new("tmux") |
| 18 | + .args(["-C", "-f", "/dev/null"]) |
| 19 | + .stdin(Stdio::piped()) |
| 20 | + .stdout(Stdio::piped()) |
| 21 | + .spawn() |
| 22 | + .context("Failed to start tmux control mode")?; |
| 23 | + |
| 24 | + let stdin = tmux.stdin.as_mut().context("Failed to get tmux stdin")?; |
| 25 | + |
| 26 | + // Create session with editor |
| 27 | + writeln!( |
| 28 | + stdin, |
| 29 | + "new-session -d -s djls-debug 'nvim tests/project/djls_app/templates/djls_app/base.html'" |
| 30 | + )?; |
| 31 | + |
| 32 | + // Add devtools pane (20% width on the right) |
| 33 | + writeln!( |
| 34 | + stdin, |
| 35 | + "split-window -t djls-debug -h -p 20 'just dev devtools record'" |
| 36 | + )?; |
| 37 | + |
| 38 | + // Split the right pane horizontally for server logs (50/50 split) |
| 39 | + writeln!( |
| 40 | + stdin, |
| 41 | + "split-window -t djls-debug:0.1 -v -p 50 'tail -f /tmp/djls.log'" |
| 42 | + )?; |
| 43 | + |
| 44 | + // Set pane titles |
| 45 | + writeln!(stdin, "select-pane -t djls-debug:0.0 -T 'Editor'")?; |
| 46 | + writeln!(stdin, "select-pane -t djls-debug:0.1 -T 'LSP DevTools'")?; |
| 47 | + writeln!(stdin, "select-pane -t djls-debug:0.2 -T 'Server Logs'")?; |
| 48 | + |
| 49 | + // Enable pane borders with titles at the top |
| 50 | + writeln!(stdin, "set -t djls-debug pane-border-status top")?; |
| 51 | + |
| 52 | + // Add custom keybind to kill session (capital K) |
| 53 | + writeln!(stdin, "bind-key K kill-session")?; |
| 54 | + |
| 55 | + // Configure status bar with keybind hints |
| 56 | + writeln!(stdin, "set -t djls-debug status on")?; |
| 57 | + writeln!(stdin, "set -t djls-debug status-position bottom")?; |
| 58 | + writeln!( |
| 59 | + stdin, |
| 60 | + "set -t djls-debug status-style 'bg=colour235,fg=colour250'" |
| 61 | + )?; |
| 62 | + |
| 63 | + // Left side: session name |
| 64 | + writeln!(stdin, "set -t djls-debug status-left '[#S] '")?; |
| 65 | + writeln!(stdin, "set -t djls-debug status-left-length 20")?; |
| 66 | + |
| 67 | + // Right side: keybind hints |
| 68 | + writeln!(stdin, "set -t djls-debug status-right ' C-b d: detach | C-b K: kill session | C-b x: kill pane | C-b z: zoom | C-b ?: help '")?; |
| 69 | + writeln!(stdin, "set -t djls-debug status-right-length 90")?; |
| 70 | + |
| 71 | + // Center: window name |
| 72 | + writeln!(stdin, "set -t djls-debug status-justify centre")?; |
| 73 | + |
| 74 | + // Focus editor pane |
| 75 | + writeln!(stdin, "select-pane -t djls-debug:0.0")?; |
| 76 | + |
| 77 | + // Exit control mode |
| 78 | + writeln!(stdin, "detach")?; |
| 79 | + stdin.flush()?; |
| 80 | + |
| 81 | + // Close stdin to signal we're done sending commands |
| 82 | + drop(tmux.stdin.take()); |
| 83 | + |
| 84 | + // Wait for control mode to finish |
| 85 | + tmux.wait()?; |
| 86 | + |
| 87 | + // Attach to session |
| 88 | + Command::new("tmux") |
| 89 | + .args(["attach-session", "-t", "djls-debug"]) |
| 90 | + .status() |
| 91 | + .context("Failed to attach to session")?; |
| 92 | + |
| 93 | + // Cleanup on exit |
| 94 | + let _ = Command::new("pkill").args(["-f", "lsp-devtools"]).output(); |
| 95 | + |
| 96 | + Ok(()) |
| 97 | +} |
0 commit comments