#!/usr/bin/env bash # share terminal session in read-only mode # exit if a command fails set -o errexit # exit if required variables are not set set -o nounset # return the exit status of the final command before a failure set -o pipefail # check for dependencies script_commands="gotty tmux" missing_counter=0 for needed_command in ${script_commands}; do if ! hash "${needed_command}" >/dev/null 2>&1; then printf "Command not found in PATH: %s\n" "${needed_command}" >&2 ((missing_counter++)) fi done if ((missing_counter > 0)); then printf "Minimum %d commands are missing in PATH, aborting.\n" "${missing_counter}" >&2 exit 1 fi ## configure gotty # listen port listen_port="${listen_port:-"1338"}" # tab name gotty_title="${gotty_title:-"Watch Me!"}" # kill any existing tmux session, and start a new one tmux has-session -t watchme && tmux kill-session -t watchme && echo "Killed old tmux session..." >/dev/null 2>&1 tmux -2 new-session -d -s watchme echo "Created new tmux session..." # disable automatic renaming tmux set-option -g allow-rename off # only resize the pane if a smaller client is actively looking at it tmux set-option -g aggressive-resize on # run gotty in window 0 tmux rename-window -t watchme:0 'GoTTY' tmux select-window -t watchme:0 tmux send-keys "gotty --title-format "${gotty_title}" --port "${listen_port}" -- tmux a -t watchme" C-m echo "Launched GoTTY..." # broadcast terminal in window 1 tmux new-window -t watchme:1 -n "${gotty_title}" tmux select-window -t watchme:1 # connect to the tmux session and show off tmux a -t watchme