Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
seekstar opened this issue Jan 28, 2024 · 0 comments
Open

Comments

@seekstar
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant