Skip to content

Instantly share code, notes, and snippets.

@tdegrunt
Forked from colmarius/tmux-tmuxinator-setup.md
Created March 3, 2020 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdegrunt/f9c3e50e2dce85fd904773abeea81ef9 to your computer and use it in GitHub Desktop.
Save tdegrunt/f9c3e50e2dce85fd904773abeea81ef9 to your computer and use it in GitHub Desktop.
Project start/stop with tmux + tmuxinator

1. Install tmux + tmuxinator

gem install tmuxinator

2. Add ~/.tmuxinator project specific configurations

# File: ~/.tmuxinator/project-name.yml

name: project-name
root: ~/Work/ProjectName
windows:
  - App:
      layout: tiled
      panes:
        - clear && cd App
        - clear && ./boot-app App
  - api:
      layout: tiled
      panes:
        - clear && cd api
        - clear && ./boot-app api
  - sso:
      layout: tiled
      panes:
        - clear && cd sso
        - clear && ./boot-app sso

3. Set your ~/.tmux.conf

Checkout this simple config and this more advanced config.

4. Add ~/bin/work script for project start/stop with tmuxinator

Latest version can be found here in my dot-files.

# File: ~/bin/work

#!/bin/bash

display_usage() {
  echo "This script is used to start tmuxinator project sessions."
  echo -e "\nSupposing you have a session: ~/.tmuxinator/project-name.yml"
  echo -e "\nExample usage:\n"
  echo -e "work start project-name"
  echo -e "work stop project-name \n"
}

if [ $# -ne 2 ]; then
  display_usage
  exit 1
fi

operation=$1
tmuxinator_config=$2

if [ $operation == "start" ]
  then
  tmux has-session -t $tmuxinator_config 2> /dev/null

  if [ $? != 0 ]
  then
    mux start $tmuxinator_config
  else
    echo "tmux: $tmuxinator_config session is already running."
  fi
fi

if [ $operation == "stop" ]
  then
  tmux has-session -t $tmuxinator_config 2> /dev/null

  if [ $? == 0 ]
  then
    for i in `seq 1 10`;
    do
      tmux send-keys -t $tmuxinator_config:$i.1 C-c C-m
      tmux send-keys -t $tmuxinator_config:$i.2 C-c C-m
      tmux send-keys -t $tmuxinator_config:$i.3 C-c C-m
    done

    tmux kill-session -t $tmuxinator_config
  else
    echo "tmux: no $tmuxinator_config session found."
  fi
fi

5. Usage

Start a project:

work start project-name

Stop a project:

work stop project-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment