aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/tmux.bash
blob: 241af526eb5b627d79174bc147e11cf4d24cc77d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Bail if no tmux(1)
if ! hash tmux 2>/dev/null ; then
    return
fi

# Attach to existing tmux session rather than create a new one if possible
tmux() {
    local -a tcmd

    # If sessions exist, default the arguments to the attach-session command
    if ! (($#)) ; then
        if command tmux has-session 2>/dev/null ; then
            tcmd=(attach-session -d)
        else
            tcmd=(new-session -s "${TMUX_SESSION:-default}")
        fi

    # Otherwise, just call tmux directly with the given arguments
    else
        tcmd=("$@")
    fi

    # Run tmux command with concluded arguments
    command tmux "${tcmd[@]}"
}