#!/usr/bin/env bash

#
# Sets up an existing tab for streaming.
# Meant to be run from within tmux in the existing window that
# should be set up for streaming.
#
# Meant to be set up with:
#
# - iTerm2: 8x zoom in
# - Amethyst: 5x expand horizontally
#
# Usage:
#   stream-layout primary
#     Set up primary tab (todo is writable)
#   stream-layout
#     Set up secondary tab (todo is readonly)
#   stream-layout quit
#     Close all open windows
#

if [ "${1:-}" = "quit" ]; then
  tmux set synchronize-panes on

  tmux send-keys C-c
  sleep 0.1
  tmux send-keys C-d
  sleep 0.1
  tmux send-keys ":qall!" Enter
  sleep 0.1
  tmux send-keys C-d

  tmux set synchronize-panes off
else
  # Right column
  tmux split-window -h
  sleep 0.3
  tmux resize-pane -x 35

  # Facecam
  tmux split-window -v
  sleep 0.3
  tmux resize-pane -y 10
  if [ "${1:-}" = "primary" ]; then
    tmux send-keys "facecam" Enter
  else
    tmux send-keys "facecam -R" Enter
  fi

  # Twitch chat
  tmux select-pane -U

  tmux split-window -v
  sleep 0.3
  tmux send-keys "npx tc connect jez_io" Enter

  # Spotify
  if command -v sp &> /dev/null; then
    tmux select-pane -U

    tmux split-window -v -l 2
    sleep 0.3
    tmux send-keys "current-song" Enter
  fi

  # To-do list
  tmux select-pane -U

  if [ "${1:-}" = "primary" ]; then
    tmux send-keys "todo" Enter "gg"
  else
    tmux send-keys "todo -R" Enter "gg"
  fi

  # Back to main
  tmux select-pane -L
fi




# ---- old layout (not full screen mode) ---
# tmux split-window -v
# sleep 0.3
# tmux resize-pane -y 10
#
# tmux select-pane -U
#
# tmux split-window -h
# sleep 0.3
# tmux resize-pane -x 35
#
# tmux split-window -v
# sleep 0.3
# tmux resize-pane -y 11
# tmux send-keys "facecam" Enter
#
# tmux select-pane -U
# tmux send-keys "todo" Enter "gg"
#
# tmux select-pane -L

# vim:ft=tmux
