'How to launch tmux –automatically– when konsole/yakuake start?

I discovered tmux possibility recently and I'm using it inside yakuake/konsole (quake-like terminal). However, I have to launch tmux manually every time I start my laptop or restart yakuake.

How to launch tmux –automatically– when yakuake/konsole start ?



Solution 1:[1]

Based on Start tmux on every shell login article from Archlinux wiki, you can start tmux on your shell with following code at the

Zsh or Bash

Add in your zsh or bash configuration (usually ~/.zshrc or ~/.bashrc) the following code and restart your session:

function start_tmux() {
    if type tmux &> /dev/null; then
        #if not inside a tmux session, and if no session is started, start a new session
        if [[ $HOST == "laptop" && -z "$TMUX" && -z $TERMINAL_CONTEXT ]]; then
            (tmux -2 attach || tmux -2 new-session)
        fi
    fi
}
start_tmux

Fish

Add in your fish configuration (usually ~/.config/fish/config.fish) the following code and restart your session:

function start_tmux
    if type tmux > /dev/null
        #if not inside a tmux session, and if no session is started, start a new session
        if test -z "$TMUX" ; and test -z $TERMINAL_CONTEXT
            tmux -2 attach; or tmux -2 new-session
        end
    end
end

start_tmux

Solution 2:[2]

A friend advice to use <terminal_emulator> -e tmux.

Konsole

It works with konsole.

I modified the property in the menu to:

konsole -e tmux

Yakuake

However it doesn't work with yakuake.

Solution 3:[3]

When yakuake is running:

qdbus org.kde.yakuake /yakuake/sessions runCommandInTerminal 0 "tmux"

Solution 4:[4]

I solved this by creating a Konsole/Yakuake profile (they're one and the same) + made it the default, in which I set up the Command to:

/usr/bin/sh -ilc "tmux attach || tmux new"

Manage profiles + where the profile is located, in case Yakuake/Konsole doesn't start up anymore: How to manage Konsole/Yakuake profile and where the file is located

Solution 5:[5]

I haven't tried with Yakuake but I have a one liner shell scripting approach to make it work with Konsole Terminal Emulator.

Konsole emulator set KONSOLE_<something> environment variable on start.

Knowing this fact, we can add this to .zshrc file

[ -z "$KONSOLE_VERSION" ] || tmux

And this will start all KONSOLE windows attached to active tmux session or create one if its the first window.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Édouard Lopez
Solution 2 Nicola Ben
Solution 3 gezpage
Solution 4 clausavram
Solution 5 avimehenwal