aboutsummaryrefslogtreecommitdiff
path: root/scripts/.scripts/tm.sh
blob: 851cd7ee18b9884d42fab80551d13263d20a6c84 (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
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# source https://github.com/Drakirus/dotfiles/blob/master/bin/tm
# abort if we're already inside a TMUX session
if [ "$TMUX" != "" ]; then
  echo "Already inside a TMUX session !!"
  exit 1
fi
# startup a "default" session if non currently exists
# tmux has-session -t _default || tmux new-session -s _default -d


SessionNb=$( tmux list-sessions -F "#S" 2>/dev/null | wc -l )
if [ $SessionNb -eq 0 ]; then
  # read -p "Enter new session name: " SESSION_NAME
  TERM=screen-256color-bce tmux new -s "Start" #"$SESSION_NAME"
else
  # present menu for user to choose which workspace to open
  PS3="Please choose your session: "
  options=($(tmux list-sessions -F "#S" 2>/dev/null) "New Session" "Independent attach")
  echo "Available Options"
  echo "------------------"
  echo " "
  select opt in "${options[@]}"
  do
    case $opt in
      "New Session")
        read -p "Enter new session name: " SESSION_NAME
        TERM=screen-256color-bce tmux new -s "$SESSION_NAME"
        break
        ;;

      "Independent attach")
        optionsATTACH=($(tmux list-sessions -F "#S" 2>/dev/null))
        echo " "
        echo "Available sessions"
        echo "------------------"
        select optATT in "${optionsATTACH[@]}"
        do
          TERM=screen-256color-bce tmux new -s "Agent_infiltré" -t $optATT
          exit 0
        done
        ;;
      *)
        TERM=screen-256color-bce tmux attach-session -t $opt
        break
        ;;
    esac
  done
fi