Skip to content

Instantly share code, notes, and snippets.

@marczych
Last active August 29, 2015 13:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marczych/10524654 to your computer and use it in GitHub Desktop.
Save marczych/10524654 to your computer and use it in GitHub Desktop.
Tmux git-scripts functions
#!/bin/sh
# Convenience functions to set the tmux session name based on branches/pull
# numbers and switches branches based on the session name.
#
# Depends on tmux and https://github.com/iFixit/git-scripts.
# (feature|hotfix) switch based on the session name.
function tswitch {
BRANCH=$(tmux display-message -p '#S' | sed 's/|.*$//')
feature switch $BRANCH
}
# Updates the session name based on the current branch/pull.
function tupdate {
BRANCH=$(git rev-parse --abbrev-ref HEAD)
PULL=$(tmux capture-pane -p | grep -E "Successfully .*#[0-9]+" | tail -1 | sed 's/^.*#//')
SESSION_NAME="$BRANCH"
if [ "$PULL" != '' ] ; then
SESSION_NAME="$SESSION_NAME|$PULL"
fi
tmux rename-session "$SESSION_NAME"
}
# Attach to an existing session matching any part of the name.
function tattach {
SESSION_NAME=$(tmux ls | sed 's/:.*$//' | grep "$1")
tmux attach -t "$SESSION_NAME"
}
@marczych
Copy link
Author

That works for me. I'll get around to moving it there in the next few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment