#!/bin/sh

# This is a simple tmux smoketest that creates a Byobu session using tmux as the backend, checks that the session was created, and then kills the session.

SESSION="test_tmux"
BYOBU_COMMAND="byobu-tmux"

if ${BYOBU_COMMAND} list-session 2>/dev/null; then
	echo >&2 "Found an unexpected byobu session!"
	exit 1
fi

# Create a byobu session
${BYOBU_COMMAND} new-session -d -s "${SESSION}"

# Get active session names (should only be ${SESSION} at this point 
session_name=$(${BYOBU_COMMAND} list-session | awk '{print $1}' | sed 's/://g')

if [ "${session_name}" != "${SESSION}" ]; then
	echo >&2 "Session is not running after trying to create a new session!"
	exit 1
fi

${BYOBU_COMMAND} kill-session -t ${SESSION}

if ${BYOBU_COMMAND} list-session 2>/dev/null; then
	echo >&2 "Found an unexpected byobu session after deleting session!"
	exit 1
fi

exit 0
