File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,12 @@ You can do a text search to change to the worktree directory.
2626$ wt < worktree-name/search-term>
2727```
2828
29+ Go to root worktree directory
30+
31+ ``` bash
32+ $ wt -
33+ ```
34+
2935List out all the worktrees.
3036
3137``` bash
Original file line number Diff line number Diff line change @@ -17,17 +17,32 @@ help_message(){
1717 echo -e " \twt <worktree-name/search-term>: search for worktree names and change to that directory."
1818}
1919
20+ goto_main_worktree () {
21+ main_worktree=$( git worktree list | awk ' NR==1 {print $1}' )
22+
23+ if [ -z $main_worktree ]; then
24+ :
25+ else
26+ echo Changing to worktree at: $main_worktree
27+ cd $main_worktree
28+ exec $( echo $SHELL )
29+ fi
30+ }
31+
2032# If the first argument is "list", show worktree list,
2133# if it is "help", then show the help message,
34+ # if it is "-", go to the main working tree,
2235# else get worktree path based on user input.
2336if [ -z ${args[0]} ]; then
2437 help_message
2538elif [ ${args[0]} == " list" ]; then
2639 worktree_list
2740elif [ ${args[0]} == " help" ]; then
2841 help_message
42+ elif [ ${args[0]} == " -" ]; then
43+ goto_main_worktree
2944else
30- directory=$( git worktree list | awk ' /' " ${args[0]} " ' / {print $1}' )
45+ directory=$( git worktree list | awk ' /' " ${args[0]} " ' / {print $1}' | awk ' NR==1 {print $1} ' )
3146fi
3247
3348# Change worktree based on user argument.
@@ -38,8 +53,7 @@ change_worktree() {
3853}
3954
4055# If directory variable is not empty then change worktree
41- if [ -z $directory ]
42- then
56+ if [ -z $directory ]; then
4357 :
4458else
4559 change_worktree
You can’t perform that action at this time.
0 commit comments