You are not logged in.

#1 2023-06-16 13:45:16

tomsk
Member
Registered: 2016-12-17
Posts: 224

[SOLVED] tmux as default terminal (multiplexer)

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; fi

it 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

#2 2023-06-16 14:16:56

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,325

Re: [SOLVED] tmux as default terminal (multiplexer)

https://wiki.archlinux.org/title/Tmux has a bunch of examples already, you're looking for a conditional destroy-unattached option.

Offline

#3 2023-06-16 17:52:49

tomsk
Member
Registered: 2016-12-17
Posts: 224

Re: [SOLVED] tmux as default terminal (multiplexer)

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

#4 2023-06-16 19:01:00

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,325

Re: [SOLVED] tmux as default terminal (multiplexer)

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

#5 2023-06-17 10:33:21

tomsk
Member
Registered: 2016-12-17
Posts: 224

Re: [SOLVED] tmux as default terminal (multiplexer)

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

#6 2023-06-17 11:21:05

tomsk
Member
Registered: 2016-12-17
Posts: 224

Re: [SOLVED] tmux as default terminal (multiplexer)

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; fi

I 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

#7 2023-06-17 12:06:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] tmux as default terminal (multiplexer)

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

#8 2023-06-17 12:11:34

tomsk
Member
Registered: 2016-12-17
Posts: 224

Re: [SOLVED] tmux as default terminal (multiplexer)

Trilby wrote:

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 smile this works, sorry Im newbie, so I didn't know how to do it, so I was scripting in zhrc file smile


I use several linux distros like: Archlinux, Ubuntu, Fedora, Linux Mint

Offline

Board footer

Powered by FluxBB