aboutsummaryrefslogtreecommitdiff
path: root/wtmux
blob: 4c6d336548b6de251b54210ef2e02e43041f7c85 (plain)
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
38
39
#
# Worktemux: tmux session wrapper
# https://robots.thoughtbot.com/a-tmux-crash-course
#
# Alternatives:
# https://github.com/tmuxinator/tmuxinator
# https://github.com/tony/tmuxp

# Default options.
opts=""

# Session selection.
if [ ! -z "$1" ]; then
  if ! tmux list-sessions 2> /dev/null | grep -q "^$1:"; then
    session="new-session -d -s $1"

    if [ "$1" = "root" ]; then
      sudo tmux attach
      exit
    elif [ -f "$HOME/.tmux/$1" ]; then
      opts="$HOME/.tmux/$1"
    elif [ -f "$HOME/.tmux/base" ]; then
      opts="$HOME/.tmux/base"
    else
      opts=""
    fi

    # Start session.
    if [ ! -z "$opts" ]; then
      tmux $session \; source-file $opts
    else
      tmux $session
    fi
  fi

  tmux attach -t $1
else
  tmux
fi