Last active
December 13, 2016 20:08
-
-
Save askhat/784dbd1b856a0e138fd6192abee67abc to your computer and use it in GitHub Desktop.
Cruise between tmux sessions easily
This file contains hidden or 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
| #!/usr/bin/env bash | |
| ARG=$1 | |
| function name { | |
| if [ -n "$ARG" ]; then | |
| echo $ARG | |
| else | |
| echo $(basename $(pwd)) | |
| fi | |
| } | |
| function sessions { | |
| echo $(tmux ls -F '#S') | |
| } | |
| function exists { | |
| if [[ $(sessions) =~ $(name) ]]; then | |
| true | |
| else | |
| false | |
| fi | |
| } | |
| function not_in_tmux { | |
| if [ -n "$TMUX" ]; then | |
| false | |
| else | |
| true | |
| fi | |
| } | |
| if exists && not_in_tmux; then | |
| tmux attach -t `name` | |
| elif exists; then | |
| tmux switch-client -t `name` | |
| else | |
| tmux new -ds `name` && tmux switch-client -t `name` | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don’t remember where I found it, but I’ve been using this without any issues for quite some time:
From the manual: The -A flag makes new-session behave like attach-session if session-name already exists.