Skip to content

Instantly share code, notes, and snippets.

@jimrhoskins
Created June 4, 2013 19:27
Show Gist options
  • Save jimrhoskins/5708777 to your computer and use it in GitHub Desktop.
Save jimrhoskins/5708777 to your computer and use it in GitHub Desktop.
A zsh function for creating/connecting to named tmux sessions
# 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