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

Attachment: pgpyGZ4REjDr5.pgp
Description: PGP signature

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

Reply via email to