]> git.immae.eu Git - perso/Immae/Config/Ansible.git/blobdiff - roles/shell/bash/templates/bashrc.j2
Add a tmux_dev command
[perso/Immae/Config/Ansible.git] / roles / shell / bash / templates / bashrc.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 %}