Update tat script to also work from within tmux

The existing script would fail if run from within tmux as the default
behavior would cause a nested tmux session which is bad. This update
detects if the current context is within tmux and properly handles this
by creating a detached session and switching to it as needed.

This properly handles all four combinations of in tmux vs out, and
session existing vs not. The behavior should remain unchanged for
existing use cases.