Skip to content

Instantly share code, notes, and snippets.

@ernesto-jimenez
Created March 20, 2015 15:23
Show Gist options
  • Save ernesto-jimenez/dea41dbd4cb877a1df70 to your computer and use it in GitHub Desktop.
Save ernesto-jimenez/dea41dbd4cb877a1df70 to your computer and use it in GitHub Desktop.
When entering a dir with a git repository, start a new tmux session for that repository or attach to the existing one if it has already been started.
# Always use the same tmux session in directories with git
attach_tmux_for_dirs_with_repos() {
if [ "$TERM" != "screen-256color" ]; then
if [ -d .git ]; then
SESSION_NAME=$(echo -n ${PWD//*\//}-tmux | tr . -)
tmux attach -t $SESSION_NAME || tmux new -s $SESSION_NAME
fi
fi
}
add-zsh-hook precmd attach_tmux_for_dirs_with_repos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment