質問

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 ?

役に立ちましたか?

解決 2

Based on the Start tmux on every shell login article from the Archlinux wiki, you can start tmux on your shell with the 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

他のヒント

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.

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

When yakuake is running:

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

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top