Created
June 4, 2013 19:27
-
-
Save jimrhoskins/5708777 to your computer and use it in GitHub Desktop.
A zsh function for creating/connecting to named tmux sessions
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
# Function for starting/resuming tmux sessions by name | |
# workon sessionname | |
# If outside of vim will connect to existing or create new session and connect | |
# If in a vim session and exists, will switch sessions | |
# If in vim and doesn't exist: fails TODO: fix this | |
workon() { | |
exist=$(tmux ls | cut -d ":" -f 1 | grep "^$1$") | |
if [[ -n $exist ]]; then | |
print Attaching to session $1 | |
if [[ -n $TMUX ]]; then | |
tmux switch-client -t $1 | |
else | |
tmux attach-session -t $1 | |
fi | |
else | |
print Creating session $1 | |
tmux new -s $1 | |
fi | |
} | |
_workon () { compadd `tmux ls | cut -d ":" -f 1`} | |
compdef _workon workon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment