git.fiddlerwoaroof.com
scripts/choose_tmux
19c31744
 #!/usr/bin/env zsh 
 tmux start
889fcda7
 
 attach_tmux () {
   TMUX_SESSION="$1"
   tmux attach -t "$TMUX_SESSION" -d
 }
 
 new_tmux () {
   TMUX_SESSION="$1"
   exec tmux new-session -s "$TMUX_SESSION"
 }
 
19c31744
 tmux_sessions() {
   echo
   tmux ls
 }
889fcda7
 
19c31744
 complete_sessions() {
   tmux_sessions | fzf --bind alt-enter:print-query -n 1 -d: | cut -d: -f1
 }
 
 if [[ x"$1" == x ]]; then
   TMUX_SESSION="$(complete_sessions)"
889fcda7
 
19c31744
   if [[ -n "$TMUX_SESSION" ]]; then
889fcda7
     attach_tmux "$TMUX_SESSION" && exit 0
   fi
 
   echo -n "No such session '$TMUX_SESSION', new session [y/N]? "
   read NEW_SESSION
   NEW_SESSION="${NEW_SESSION/Y/y}"
 
   if [[ x"${NEW_SESSION[1]}" == x'y' ]]; then
     new_tmux "$TMUX_SESSION"
   fi
 
   echo "Either you decided not to create a new session or something went _horribly_ wrong!"
   read BOB
 else
   attach_tmux "$1" || new_tmux "$1"
 fi