#!/usr/bin/env sh
#
# usage: tmux-switch-session [<name>]
#
# switches to the tmux session that starts with the name given,
# or to the previously attached session when name is blank.

set -e

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  sed -ne '/^#/!q;s/.\{1,2\}//;1d;p' <"$0"
  exit 0
fi

if [ -z "$1" ]; then
  # if command -v fzf >/dev/null 2>&1; then
  #   tmux list-sessions -F '#{session_activity}:#{session_name}' \
  #     | sort -nr | cut -d ':' -f 2 \
  #     | grep -v "^$(tmux display-message -p '#S')$" \
  #     | fzf --reverse | xargs tmux switch-client -t
  # else
  tmux switch-client -l
  # fi
else
  tmux switch-client -t "$1"
fi
