]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blob - roles/contexts/fretlink/files/scripts/fl_tmux_dev
174c4a725028d914dab2619dfc501211e67c399f
[perso/Immae/Config/Ansible.git] / roles / contexts / fretlink / files / scripts / fl_tmux_dev
1 #!/bin/bash
2
3 tmux_conf() {
4 tmux -f $XDG_CONFIG_HOME/tmux/tmux.conf "$@"
5 }
6
7 type="${1:-bash}"
8 if [ -n "$TMUX" ]; then
9 m=switch-client
10 else
11 m=attach-session
12 fi
13
14 case "$type" in
15 "bash") start_dir="$HOME";;
16 "remote") start_dir="$HOME";;
17 "puppet") start_dir="/etc/puppetlabs/code"
18 esac
19
20 if tmux has-session -t "$type" 2>/dev/null; then
21 tmux $m -t "$type"
22 else
23 if [ "$type" = "remote" ]; then
24 tmux_conf new-session -d -c $start_dir -s "$type" mosh immae.eu \; \
25 $m -t "$type"
26 elif [ -n "$start_dir" ]; then
27 tmux_conf new-session -d -c $start_dir -s "$type" \; \
28 $m -t "$type" \; \
29 new-window -c $start_dir
30 elif [ -d "$HOME/workdir/$type" ]; then
31 tmux_conf new-session -d -c "$HOME/workdir/$type" -s "$type" \; \
32 $m -t "$type" \; \
33 send-keys "../start" C-m \; \
34 rename-window "running" \; \
35 new-window -c "$HOME/workdir/$type"
36 else
37 echo "Unknown session" >&2
38 exit 1
39 fi
40 fi