Created
March 20, 2024 19:58
-
-
Save socketbox/665d1a91b86e93a58a0258c44ac56ef2 to your computer and use it in GitHub Desktop.
Add a git worktree within a workflow that uses tmux
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/zsh | |
set -euo pipefail | |
#check to see that we're in the worktree root that contains the .bare directory | |
if [ ! -d .bare ]; then | |
echo "This script must be run from the root of the worktree" | |
exit 1 | |
fi | |
#check if an argument was passed to the script and if not print usage | |
if [ $# -eq 0 ]; then | |
echo "Usage: git_worktree_add.sh <new_worktree_name>" | |
exit 1 | |
fi | |
#create a new tmux window using the first argument to the script | |
tmux new-window -n $1 | |
#change to the new window | |
tmux select-window -t $1 | |
#sleep for 2 seconds to allow the new shell to be created | |
sleep 2 | |
#using the newly created shell of the new window, run the git worktree add command | |
tmux send-keys "git worktree add $1" C-m && tmux send-keys "cd $1" C-m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment