Last active
August 29, 2015 13:59
-
-
Save marczych/10524654 to your computer and use it in GitHub Desktop.
Tmux git-scripts functions
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
#!/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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That works for me. I'll get around to moving it there in the next few days.