tmux '"' now toggles a scratch session
dblume

dblume commited on 2025-07-19 13:14:18
Showing 1 changed files, with 13 additions and 0 deletions.


Either use <leader>d to detach to send the same <leader>"
to toggle. This lets the scratch session stay around.
Handy for REPLs like bc and Python.
... ...
@@ -42,6 +42,19 @@ bind -n M-l select-pane -R
42 42
 #bind o popup -E -d "#{pane_current_path}" -w 90% -h 90% "opencode"
43 43
 bind b popup -E -w 80% -h 45% "bc -l"
44 44
 
45
+# https://www.reddit.com/r/tmux/comments/olgte7/comment/jz4t9rc/
46
+# Toggle scratch session.
47
+# Create a detached session and disable the status line before attaching to it
48
+bind '"' if -F '#{==:#{session_name},scratch}' { 
49
+    detach-client 
50
+  } { 
51
+    if "tmux has-session -t scratch" {
52
+      popup -E -w 80% "tmux attach-session -t scratch"
53
+    } {
54
+      popup -E -w 80% "tmux new-session -d -c '#{pane_current_path}' -s scratch && tmux set-option -t scratch status off && tmux attach-session -t scratch"
55
+    }
56
+}
57
+
45 58
 # (Removed) Use Alt-arrow keys without prefix key to switch panes
46 59
 # Note vim's Copilot plugin uses M-Right for "accept suggested word"
47 60
 #bind -n M-Right select-pane -R
48 61