-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.wt-switch
40 lines (35 loc) · 1.21 KB
/
.wt-switch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function load_project_dir() {
local currentDir=$(pwd)
while [[ "$currentDir" != "$HOME" ]]; do
if [[ -f "$currentDir/.gwtconfig" ]]; then
PROJECTS_DIR=$(head -n 1 "$currentDir/.gwtconfig" | sed 's:/*$::')
return
else
# Move to the parent directory
currentDir=$(dirname "$currentDir")
fi
done
echo "No .gwtconfig file found in the current or any parent directories."
return 1
}
function gwt() {
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
echo "Usage: gwt <project-name> <branch-name>"
return 1
fi
# Load PROJECTS_DIR from .gwtconfig
load_project_dir || return 1
local projectName="$1"
local branchName="$2"
local worktreePath="${PROJECTS_DIR}/${projectName}/${branchName}"
if [[ ! -d "$worktreePath" ]]; then
echo "Worktree for branch '$branchName' in project '$projectName' does not exist at $worktreePath."
return 1
fi
if cd "$worktreePath"; then
echo "Switched to the worktree for branch '$branchName' in project '$projectName'."
else
echo "Failed to switch to the worktree for branch '$branchName' in project '$projectName'."
return 1
fi
}