]> git.immae.eu Git - perso/Immae/Config/Ansible.git/commitdiff
Add a tmux_dev command
authorIsmaël Bouya <ismael.bouya@fretlink.com>
Thu, 8 Nov 2018 08:47:19 +0000 (09:47 +0100)
committerIsmaël Bouya <ismael.bouya@fretlink.com>
Thu, 8 Nov 2018 08:47:19 +0000 (09:47 +0100)
roles/shell/bash/templates/bashrc.j2
roles/tools/templates/tmux.conf.j2

index 99ed55f9919c2cb7dbcdc10069003df462e4e77e..742e1e02e6c79fc5d35f3930580502f98879bb24 100644 (file)
@@ -45,6 +45,43 @@ function dev_prompt() {
     echo "{$FRETLINK_ENV} "
   fi
 }
+
+function tmux_dev() {
+  type="${1:-bash}"
+  if [ -n "$TMUX" ]; then
+    m=switch-client
+  else
+    m=attach-session
+  fi
+
+  if tmux has-session -t "$type" 2>/dev/null; then
+    tmux $m -t "$type"
+  else
+    if [ "$type" = "bash" ]; then
+      tmux new-session -d -s "$type"
+      tmux $m -t "$type"
+    else
+      tmux 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"
+    fi
+  fi
+}
+
+_tmux_dev() {
+  COMPREPLY=()
+  local cur="${COMP_WORDS[COMP_CWORD]}"
+  prefix="$HOME/workdir/"
+  local IFS=$'\n'
+  local items=($(compgen -W "bash" -- $cur) $(compgen -d $prefix$cur))
+  for item in ${items[@]}; do
+    [[ $item == $prefix.* ]] && continue
+    COMPREPLY+=("${item#$prefix}")
+  done
+}
+complete -o filenames -F _tmux_dev tmux_dev
 ##### /Fretlink
 {% endif %}
 
index 8aad615ee7e41c9975ea7b6ce21414711dbbae59..a7ac4ceed7f601c80606fd6234f6fa0f534067d1 100644 (file)
@@ -65,24 +65,3 @@ set-window-option -g window-status-bell-style fg=yellow,bold,underscore
 set -g default-terminal screen-256color
 
 set -g mouse on
-
-{% if role.get(profile) == "fretlink" %}
-new-session -A -c "$HOME/workdir/admin-root" -s admin-root
-send-keys "../start" C-m
-rename-window "running"
-new-window
-new-session -A -c "$HOME/workdir/carrier-directory" -s carrier-directory
-send-keys "../start" C-m
-rename-window "running"
-new-window
-new-session -A -c "$HOME/workdir/notifier" -s notifier
-send-keys "../start" C-m
-rename-window "running"
-new-window
-new-session -A -c "$HOME/workdir/geodata" -s geodata
-new-session -A -c "$HOME/workdir/app" -s app
-send-keys "../start" C-m
-rename-window "running"
-new-window
-select-window -t 1
-{% endif %}