You are not logged in.
Hello,
I use zsh as my shell, and I would like to go into tmux everytime I open terminal, so I added into beginning of .zshrc file this:
if [ "$TMUX" = "" ]; then tmux; fiit works, but tmux keeps running if I close terminal, so my desired behavior should be that when I close terminal it will close tmux session too, unless it is specifically named somehow (so if I name that session somehow I would like to keep it in background, so I can later reconnect).
Last edited by tomsk (2023-06-17 12:11:56)
I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint
Offline
https://wiki.archlinux.org/title/Tmux has a bunch of examples already, you're looking for a conditional destroy-unattached option.
Offline
Doesn't destroy-unattached destroy all unattached sessions? Even those which are named?
I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint
Offline
you're looking for a conditional destroy-unattached option.
You set that for the sessions you want to lose and not for the ones you seek to re-attach to.
The name is really not relevant, every session has a "name" - whether that's a number or "pornwatch" techincally doesn't matter.
Offline
So technically I will destroy all sessions which are just numbers? Because new sessions are just numbers.
I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint
Offline
I tried it like this:
# Destroy all tmux sessions with names consisting of just numbers
function destroy_numbered_tmux_sessions() {
# Destroy all tmux sessions with names consisting of just numbers
tmux list-sessions -F "#S" | grep -E '^[0-9]+$' | xargs -I {} tmux kill-session -t {}
}
# Call the function to destroy numbered sessions
destroy_numbered_tmux_sessions
if [ "$TMUX" = "" ]; then tmux; fiI added it at the beginning of .zshrc file, but now when I open terminal I get:
no server running on /tmp/tmux-1000/default
[exited]
➜ ~ I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint
Offline
What's with all that? How about just using "destroy-unattached" as suggested just for those sessions in which you want it set:
if [ "$TMUX" = "" ]; then tmux new \; set-option destroy-unattached; fi"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
What's with all that? How about just using "destroy-unattached" as suggested just for those sessions in which you want it set:
if [ "$TMUX" = "" ]; then tmux new \; set-option destroy-unattached; fi
ah okay
this works, sorry Im newbie, so I didn't know how to do it, so I was scripting in zhrc file ![]()
I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint
Offline