summaryrefslogtreecommitdiffstats
path: root/bashrc/bin/t
blob: 3919af49e5b9e9bbe91cc982b820821636b6c59b (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
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash

real_tmux() {
    if [ -f "${HOME}/.dotfiles/tmux/tmux.conf" ]; then
        \tmux -f "${HOME}/.dotfiles/tmux/tmux.conf" -S "${HOME}/.dotfiles/tmux/socket" "$@"
    else
        \tmux "$@"
    fi
}

exec_real_tmux() {
    if [ -f "${HOME}/.dotfiles/tmux/tmux.conf" ]; then
        exec \tmux -f "${HOME}/.dotfiles/tmux/tmux.conf" -S "${HOME}/.dotfiles/tmux/socket" "$@"
    else
        exec \tmux "$@"
    fi
}


if [[ "x$1" == x ]] ; then
	real_tmux list-sessions ||
	{
		real_tmux new-session -d
	}

	exec_real_tmux attach-session -d
fi

if [ -z "$2" -a "$1" != "att" -a "$1" != "ls" ]; then
	if teal_tmux has-session -t "$1"; then
	    exec exec_real_tmux attach-session -t "$1"
	else
	    exec exec_real_tmux new-session -s "$1"
	fi
fi

exec_real_tmux $@