aboutsummaryrefslogtreecommitdiffstats
path: root/bin/atmux
blob: 7601693afeff185f26e1d43ffaef922a4a30203e (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash

if [ -e $HOME/bin/functions.sh ]
then
  . $HOME/bin/functions.sh
else
  echo "functions.sh not found"
  exit 0
fi

# override tmux
tmux='tmux'

## CONFIGURATION
# session name
sn=${1:-atmux}

# try to attach earlier session
tmux attach-session -t $sn && exit 0
#or continue

# default path
case $sn in
  # window definitions
  # path:command:custom-name
  "thesis")
    dpath=/home/konni/dropbox/documents/uni/12ss/BA/breite-quellen/thesis
    windows="-:-"
    windows+="matlab:echo bla"
    ;;
  "mako")
    dpath=/extra/src/cyanogenmod-10.1
    dcmd=". environment_mako"
    windows="-:-"
    windows+="-:-"
    windows+=" device/lge/mako:-"
    windows+=" out/target/product/mako:-"
    ;;
  "ville_dev")
    dpath=/extra/src/cyanogenmod-10.1
    dcmd=". environment_ville"
    windows="-:-"
    windows+=" -:-"
    windows+=" device/htc/ville:-"
    windows+=" device/htc/msm8960-common:-"
    windows+=" kernel/htc/msm8960:-"
    windows+=" vendor/htc:-"
    windows+=" out/target/product/ville:-"
    ;;
  "ville")
    dpath=/extra/src/cyanogenmod-jellybean
    dcmd=". environment_ville"
    windows="-:-"
    windows+=" -:-"
    windows+=" device/htc/ville:-"
    windows+=" device/htc/msm8960-common:-"
    windows+=" kernel/htc/msm8960:-"
    windows+=" vendor/htc:-"
    windows+=" out/target/product/ville:-"
    ;;
  *)
    dpath=$HOME
    windows="-:-"
esac


# enter default path
mute pushd $dpath

# prepare windows
num=1
for window in $windows
do
  # parse configuration
  read wpath wcmd <<< $(echo $window | sed 's/:/\ /g')

  # set path
  unset tpath
  if [ $wpath != "-" ]
  then
    tpath=$wpath
  fi


  if [ $num -eq 1 ]
  then
    # start new session
    $tmux new-session -d -s "$sn" $tname
    # set default path for new windows
    $tmux set-option -t "$sn" default-path $dpath
  else
    # create new window in session
    $tmux new-window -t "$sn:$num" $tname
  fi

  # execute default command
  if [ -n "$dcmd" ]
  then
    $tmux send-keys -t "$n:$num" "$dcmd" C-m
  fi

  # change path
  if [ -n "$tpath" ]
  then
    $tmux send-keys -t "$n:$num" "cd $tpath" C-m
  fi

  # execute custom command
  unset tcmd
  if [ "$wcmd" != "-" ]
  then
    tcmd=$wcmd
    $tmux send-keys -t "$n:$num" "$tcmd" C-m
  fi

  let num=num+1
done

# select window #1 and attach to session
$tmux select-window -t "$sn:1"
$tmux attach-session -t "$sn"