Skip to content

How to get the name of the monitored session in the custom command? #55

@seekstar

Description

@seekstar

I have many sessions on my server, so I want to get the session name of the monitored session and attach it to the notification email. I tried tmux display-message -p '#S' (https://superuser.com/a/410197/1677998):

set -g @tnotify-custom-cmd 'echo $(tmux display-message -p \#S) finishes" | s-nail --subject="tmux complete notification" [email protected]'

However, it seems that the attached session is the last attached session instead of the monitored session. Then I tried to get the tty name of the monitored session and find the corresponding session (https://superuser.com/a/1202709/1677998):

# ~/session-name.sh

tty=$(tty)
#echo $tty
for s in $(tmux list-sessions -F '#{session_name}' 2>/dev/null); do
    tmux list-panes -F '#{pane_tty} #{session_name}' -t "$s"
done | grep "$tty " | awk '{print $2}'
set -g @tnotify-custom-cmd 'echo "\"$(bash $HOME/session-name.sh)\" finishes" | s-nail --subject="tmux complete notification" [email protected]'

However, tty=$(tty) returns a not a tty result.

I also tried https://superuser.com/a/1357132/1677998:

if [[ -n "$TMUX_PANE" ]]; then
    session_name=$(tmux list-panes -t "$TMUX_PANE" -F '#S' | head -n1)
fi

However, TMUX_PANE is not defined.

Is there any way to get the session name of the monitored session in the custom command? I need this because attaching up to ten sessions one by one to find the one that finishes is very painful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions