-
-
Save alejandrociatti/8f51fad393599e589ffc495047fa4e12 to your computer and use it in GitHub Desktop.
Worktrees `wt` shortcut
This file contains hidden or 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
| # Worktrees function START | |
| # # Git worktree helper function: wt <feature-name> | |
| wt() { | |
| emulate -L zsh # localise options for zsh | |
| set -e | |
| local project_dir | |
| project_dir=$(git rev-parse --show-toplevel 2>/dev/null) || { | |
| echo "β Not inside a Git repository." | |
| return 1 | |
| } | |
| local project_name feature_name worktree_parent worktree_path | |
| project_name="${project_dir:t}" | |
| feature_name="$1" | |
| if [[ -z "$feature_name" ]]; then | |
| echo "β Usage: wt <feature-name>" | |
| return 1 | |
| fi | |
| worktree_parent="${project_dir:h}/${project_name}-worktrees" | |
| worktree_path="${worktree_parent}/${feature_name}" | |
| mkdir -p "$worktree_parent" | |
| git -C "$project_dir" worktree add -b "$feature_name" "$worktree_path" || return 1 | |
| if [[ -f "$project_dir/.env" ]]; then | |
| cp "$project_dir/.env" "$worktree_path/.env" | |
| echo "π Copied .env into worktree." | |
| fi | |
| if [[ -f "$project_dir/.local.env" ]]; then | |
| cp "$project_dir/.local.env" "$worktree_path/.local.env" | |
| echo "π Copied .local.env into worktree." | |
| fi | |
| local hidden_dirs=(.instrumental .agent_os .claude .cursor) | |
| for dir in $hidden_dirs; do | |
| if [[ -d "$project_dir/$dir" ]]; then | |
| cp -R "$project_dir/$dir" "$worktree_path/$dir" | |
| echo "π Copied $dir into worktree." | |
| fi | |
| done | |
| cd "$worktree_path" || return 1 | |
| npm install | |
| mix deps.get && mix compile | |
| if command -v cursor &>/dev/null; then | |
| cursor "$worktree_path" & | |
| else | |
| echo "π‘ Tip: Install Cursor or open manually in your editor." | |
| fi | |
| echo "β Worktree '$feature_name' created at $worktree_path and checked out." | |
| } | |
| # Worktrees END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment