summaryrefslogtreecommitdiff
path: root/roles/contexts/fretlink/files/scripts/fl_tmux_dev
blob: 174c4a725028d914dab2619dfc501211e67c399f (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
38
39
40
#!/bin/bash

tmux_conf() {
  tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf "$@"
}

type="${1:-bash}"
if [ -n "$TMUX" ]; then
  m=switch-client
else
  m=attach-session
fi

case "$type" in
  "bash") start_dir="$HOME";;
  "remote") start_dir="$HOME";;
  "puppet") start_dir="/etc/puppetlabs/code"
esac

if tmux has-session -t "$type" 2>/dev/null; then
  tmux $m -t "$type"
else
  if [ "$type" = "remote" ]; then
    tmux_conf new-session -d -c $start_dir -s "$type" mosh immae.eu \; \
        $m -t "$type"
  elif [ -n "$start_dir" ]; then
    tmux_conf new-session -d -c $start_dir -s "$type" \; \
        $m -t "$type" \; \
        new-window -c $start_dir
  elif [ -d "$HOME/workdir/$type" ]; then
    tmux_conf new-session -d -c "$HOME/workdir/$type" -s "$type" \; \
        $m -t "$type" \; \
        send-keys "../start" C-m \; \
        rename-window "running" \; \
        new-window -c "$HOME/workdir/$type"
  else
    echo "Unknown session" >&2
    exit 1
  fi
fi