Skip to content

Instantly share code, notes, and snippets.

@nvahalik
Created October 29, 2019 21:19
Show Gist options
  • Save nvahalik/36108d4b892b6f66982537235f9cf462 to your computer and use it in GitHub Desktop.
Save nvahalik/36108d4b892b6f66982537235f9cf462 to your computer and use it in GitHub Desktop.
git-split-commit
STAGED_CHANGES=`git status -s --untracked=no --porcelain | grep -v '^[\s\?]' | wc -l`
if [ "$STAGED_CHANGES" -eq 0 ]; then
echo "Nothing to commit. Quitting."
exit;
fi;
if [ "$TMUX" == "" ]; then
SESS="sc$$"
tmux new-session -d -s "$SESS" 'exec git diff --cached'
tmux rename-window -t "$SESS" 'Diff'
tmux select-window -t "$SESS":0
tmux split-window -t "$SESS" -h 'exec git commit'
tmux send-keys -t "$SESS:0" -l 1G
tmux send-keys -t "$SESS:0" -l i
tmux set-hook -t "$SESS" pane-exited 'kill-session -t $SESS'
tmux -2 attach-session -t $SESS
else
tmux split-window -t "$TMUX_PANE" -h 'exec git commit'
tmux send-keys -l 1G
tmux send-keys -l i
tmux set-hook pane-exited 'send-keys -t $TMUX_PANE q'
git diff --cached
fi;
git --no-pager log -n 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment