Skip to content

Instantly share code, notes, and snippets.

@sprig
Last active December 21, 2015 21:08
Show Gist options
  • Save sprig/6365905 to your computer and use it in GitHub Desktop.
Save sprig/6365905 to your computer and use it in GitHub Desktop.
Select a tmux session from a given server and attach to it.
## Select a tmux session from a given tmux server and attach to it.
TSERVER=$1
SSTRING=$(if [ $TSERVER ]; then echo "-L $TSERVER"; else echo ""; fi)
SESSIONS=$(tmux $SSTRING ls|sed -E 's/^(.*?): .*/\1/'|xargs echo)
TSERVER=$(if [ $TSERVER ]; then echo $TSERVER; else echo "the default server"; fi)
echo "Available sessions on $TSERVER:"
select opt in $SESSIONS "Quit"; do
case $opt in
Quit)
break;;
*)
echo $opt
if [ $opt ]; then
tmux $SSTRING att -t $opt
exit 0
else
echo "Error: Invalid option!"
fi
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment