Last active
December 21, 2015 21:08
-
-
Save sprig/6365905 to your computer and use it in GitHub Desktop.
Select a tmux session from a given server and attach to it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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