-
-
Save stdrc/1994e21019d25fb10bcd1983415882b1 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Git Worktree Manager | |
| dir_name=$(basename "$(pwd)") | |
| worktrees_dir=$(pwd)/../$dir_name.worktrees | |
| list() { | |
| git worktree list "$@" | |
| } | |
| new() { | |
| local branch_name=$1 | |
| shift | |
| mkdir -p "$worktrees_dir" | |
| git worktree add -b "$branch_name" "$worktrees_dir/$branch_name" "$@" | |
| } | |
| delete() { | |
| local branch_name=$1 | |
| shift | |
| git worktree remove "$worktrees_dir/$branch_name" "$@" | |
| } | |
| open() { | |
| local branch_name=$1 | |
| cursor "$worktrees_dir/$branch_name" | |
| } | |
| # Command alias mapping | |
| case "${1:-}" in | |
| ls) | |
| shift | |
| list "$@" | |
| ;; | |
| del|remove|rm) | |
| shift | |
| delete "$@" | |
| ;; | |
| add) | |
| shift | |
| new "$@" | |
| ;; | |
| list|new|delete|open) | |
| "$@" | |
| ;; | |
| *) | |
| echo "Usage: wt [list|new|delete|open] [args...]" | |
| echo "" | |
| echo "Commands:" | |
| echo " list List all worktrees" | |
| echo " new <branch> Create new worktree with branch" | |
| echo " delete <branch> Delete worktree" | |
| echo " open <branch> Open worktree in Cursor" | |
| exit 1 | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment