mirror of
https://github.com/prdlk/dotfiles.git
synced 2026-11-02 19:32:43 +00:00
fix(cli): ghostty-tmux skips pj task sessions; confirm ctrl-c before stopping bg tasks
This commit is contained in:
1 parent
954e1e1ae0
commit
04ade162b4
5 files changed
+20
-16
No files matched your search
@@ -2,8 +2,11 @@
|
||||
# Ghostty's `command`: every Ghostty window gets its own tmux session, never
|
||||
# a mirror of another window's. Reclaim the oldest detached session (left by
|
||||
# a closed window, or restored by tmux-continuum after a reboot) so closed
|
||||
# windows don't pile up sessions; otherwise start a new one. The first window
|
||||
# after boot starts the server, which is what triggers continuum's restore.
|
||||
# windows don't pile up sessions; otherwise start a new one. pj-palette's
|
||||
# background task sessions (@pj_task, named <session>:<task>) are never
|
||||
# reclaimed, and targets use the session id since names may contain ':'.
|
||||
# The first window after boot starts the server, which is what triggers
|
||||
# continuum's restore.
|
||||
# ponytail: two windows opened in the same instant can claim the same detached
|
||||
# session; take a lock (flock) here if that ever bites.
|
||||
|
||||
@@ -12,8 +15,8 @@
|
||||
# (bun for tmux-palette, fzf, zoxide).
|
||||
[[ -d $HOME/.local/share/mise/shims ]] && PATH="$HOME/.local/share/mise/shims:$PATH"
|
||||
|
||||
oldest=$(tmux list-sessions -f '#{==:#{session_attached},0}' \
|
||||
-F '#{session_created} #{session_name}' 2>/dev/null | sort -n | head -1 | cut -d' ' -f2-)
|
||||
oldest=$(tmux list-sessions -f '#{&&:#{==:#{session_attached},0},#{!:#{@pj_task}}}' \
|
||||
-F '#{session_created} #{session_id}' 2>/dev/null | sort -n | head -1 | cut -d' ' -f2)
|
||||
|
||||
[[ -n $oldest ]] && exec tmux attach-session -t "=$oldest"
|
||||
[[ -n $oldest ]] && exec tmux attach-session -t "$oldest"
|
||||
exec tmux new-session
|
||||
@@ -25,10 +25,10 @@
|
||||
# Long-running items (dev/start/serve/watch/preview tasks, compose up) run in a
|
||||
# detached session named <session>:<tool-and-command> (leetcode:bun-run-dev),
|
||||
# shown in a popup: q hides the popup and leaves the task running, ctrl-c
|
||||
# stops the task and ends its session. Running ones are listed first, under
|
||||
# Running, to bring them back. tmux.conf's prefix + a starts omp the same way
|
||||
# (<session>:omp); omp needs q, so its popup hides with ctrl-c (or prefix + a)
|
||||
# and ctrl-q quits it.
|
||||
# asks for confirmation, then stops the task and ends its session. Running
|
||||
# ones are listed first, under Running, to bring them back. tmux.conf's
|
||||
# prefix + a starts omp the same way (<session>:omp); omp needs q, so its
|
||||
# popup hides with ctrl-c (or prefix + a) and ctrl-q quits it.
|
||||
|
||||
set -uo pipefail
|
||||
self=$(readlink -f "$0")
|
||||
@@ -86,10 +86,11 @@ case ${1-} in
|
||||
set -t "$id" detach-on-destroy on
|
||||
# Each session gets a key table for its hide/quit keys; other keys
|
||||
# reach the program. A task's output takes no input, so q hides and
|
||||
# ctrl-c stops the task. Interactive programs (omp) need q and typing,
|
||||
# so ctrl-c hides and ctrl-q kills the session.
|
||||
# ctrl-c (after a y/n confirm) stops the task. Interactive programs
|
||||
# (omp) need q and typing, so ctrl-c hides and ctrl-q kills the session.
|
||||
if [ "$1" = "$self" ]; then
|
||||
tmux set -t "$id" key-table pj-task \; bind -T pj-task q detach-client
|
||||
tmux set -t "$id" key-table pj-task \; bind -T pj-task q detach-client \; \
|
||||
bind -T pj-task C-c confirm-before -p 'Stop #{session_name}? (y/n)' 'send-keys C-c'
|
||||
else
|
||||
tmux set -t "$id" key-table pj-app \; bind -T pj-app C-c detach-client \; \
|
||||
bind -T pj-app C-q kill-session
|
||||
|
||||
Reference in new issue
Block a user