Well we don't have a client_pid format but perhaps you can get the tty with ps 
then do eg tmux lsc -F "#{client_tty} #{session_id}"|grep whatevertty

If you always detach with key bindings could also consider this instead:

set -g destroy-unattached on
bind d set destroy-unattached off\; detach

-------- Original message --------
From: Kasza Péter <mr.sch...@gmail.com> 
Date: 05/04/2014  21:21  (GMT+00:00) 
To: tmux-users@lists.sourceforge.net 
Subject: Using tmux in every terminal 
 
Dear tmux-users list!

I've been experimenting with starting tmux by default in all my
terminals. What I would like to do is to kill the session if the
terminal is closed with a SIGTERM/SIGKILL, but also be able to detach
from it as usual. If the terminal is closed, the shell should close the
current session viewed in tmux, but only if there are no other clients
attached to it.

By starting tmux in every shell I could quickly switch between them by
switching sessions and also I could detach if I want to leave something
running.

I'm using zsh and came up with the following method:

~/.profile:

> zshexit() {
>     if [[ -z "$TMUX_DONT_EXIT" ]]; then
>         tmux kill-session -t ${TMUX_SESSION}
>     fi
> }
> 
> if [[ -z "$TMUX" ]]; then
>     export TMUX_SESSION="shell-`printf "%04x" "$RANDOM"`"
>     tmux new-session -s ${TMUX_SESSION}
>     export TMUX_DONT_EXIT=true
>     exit
> else
>     unset TMUX_SESSION
> fi

This works somewhat, but I can only kill the session that was originally
started in the terminal, because I couldn't figure out a way to get the
currently viewed session's name from the client's pid. Is there a way to
do this using the current command-line options? If I had the
session-name, then implementing this would be quite easy.

Thanks!

-- 
Best Regards,
Peter Kasza

http://www.iit.uni-miskolc.hu/~kasza1
mr.sch...@gmail.com

()  ascii ribbon campaign - against html e-mail
/\  www.asciiribbon.org   - against proprietary attachments

------------------------------------------------------------------------------

_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users
------------------------------------------------------------------------------
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to