mirror of
https://github.com/theniceboy/.config.git
synced 2026-02-22 12:55:39 +08:00
add M-w hotkey to watch pane process and notify on completion
This commit is contained in:
parent
4a5044a949
commit
3e14a478a6
4 changed files with 58 additions and 0 deletions
|
|
@ -187,6 +187,7 @@ bind > swap-pane -D
|
|||
bind < swap-pane -U
|
||||
bind | swap-pane
|
||||
bind -n M-b run-shell 'val=$(tmux show -wv @unread 2>/dev/null); if [ "$val" = "1" ]; then tmux set -wu @unread; else tmux set -w @unread 1; fi; tmux refresh-client -S'
|
||||
bind -n M-w run-shell -b 'val=$(tmux show -wv @watching 2>/dev/null); if [ "$val" = "1" ]; then tmux set -wu @watching; tmux refresh-client -S; else ~/.config/tmux/scripts/watch_pane.sh "#{pane_id}" "#{window_id}"; fi'
|
||||
bind -n M-m run-shell "test -f ~/.config/agent-tracker/scripts/focus_latest_notified.sh && bash ~/.config/agent-tracker/scripts/focus_latest_notified.sh || true"
|
||||
bind -n M-M run-shell "test -f ~/.config/agent-tracker/scripts/focus_last_origin.sh && bash ~/.config/agent-tracker/scripts/focus_last_origin.sh || true"
|
||||
bind Space run-shell "~/.config/tmux/scripts/toggle_orientation.sh"
|
||||
|
|
|
|||
41
tmux/scripts/watch_pane.sh
Executable file
41
tmux/scripts/watch_pane.sh
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
pane_id="$1"
|
||||
window_id="$2"
|
||||
|
||||
[[ -z "$pane_id" || -z "$window_id" ]] && exit 1
|
||||
|
||||
shells="bash zsh fish sh dash ksh tcsh csh"
|
||||
|
||||
is_shell() {
|
||||
local cmd="$1"
|
||||
for s in $shells; do
|
||||
[[ "$cmd" == "$s" ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
current_cmd=$(tmux display-message -p -t "$pane_id" '#{pane_current_command}' 2>/dev/null || true)
|
||||
[[ -z "$current_cmd" ]] && exit 0
|
||||
|
||||
if is_shell "$current_cmd"; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
tmux set -w -t "$window_id" @watching 1 2>/dev/null || true
|
||||
tmux refresh-client -S
|
||||
|
||||
while true; do
|
||||
sleep 1
|
||||
watching=$(tmux show -wv -t "$window_id" @watching 2>/dev/null || true)
|
||||
[[ "$watching" != "1" ]] && exit 0
|
||||
cmd=$(tmux display-message -p -t "$pane_id" '#{pane_current_command}' 2>/dev/null || true)
|
||||
if [[ -z "$cmd" ]] || is_shell "$cmd"; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
tmux set -wu -t "$window_id" @watching 2>/dev/null || true
|
||||
tmux set -w -t "$window_id" @unread 1 2>/dev/null || true
|
||||
tmux refresh-client -S
|
||||
|
|
@ -70,13 +70,22 @@ fi
|
|||
get_session_icon() {
|
||||
local sid="$1"
|
||||
|
||||
# Check for manual @watching on any window in this session
|
||||
local watching_win
|
||||
watching_win=$(tmux list-windows -t "$sid" -F '#{@watching}' 2>/dev/null | grep -m1 '^1$' || true)
|
||||
|
||||
# Check for manual @unread on any window in this session
|
||||
local unread_win
|
||||
unread_win=$(tmux list-windows -t "$sid" -F '#{@unread}' 2>/dev/null | grep -m1 '^1$' || true)
|
||||
|
||||
if [[ -n "$unread_win" ]]; then
|
||||
printf '🔔'
|
||||
return
|
||||
fi
|
||||
if [[ -n "$watching_win" ]]; then
|
||||
printf '⏳'
|
||||
return
|
||||
fi
|
||||
|
||||
[[ -z "$tracker_state" ]] && return
|
||||
local result
|
||||
|
|
|
|||
|
|
@ -4,6 +4,13 @@ set -euo pipefail
|
|||
window_id="$1"
|
||||
[[ -z "$window_id" ]] && exit 0
|
||||
|
||||
# Check manual @watching flag
|
||||
watching=$(tmux show -wv -t "$window_id" @watching 2>/dev/null || true)
|
||||
if [[ "$watching" == "1" ]]; then
|
||||
printf '⏳'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check manual @unread flag
|
||||
unread=$(tmux show -wv -t "$window_id" @unread 2>/dev/null || true)
|
||||
if [[ "$unread" == "1" ]]; then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue