Skip to content

Commit bd51780

Browse files
committed
Feature: chanage to root worktree.
Fix: multiline directory name capture error.
1 parent a5ee256 commit bd51780

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
2935
List out all the worktrees.
3036

3137
```bash

wt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff 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.
2336
if [ -z ${args[0]} ]; then
2437
help_message
2538
elif [ ${args[0]} == "list" ]; then
2639
worktree_list
2740
elif [ ${args[0]} == "help" ]; then
2841
help_message
42+
elif [ ${args[0]} == "-" ]; then
43+
goto_main_worktree
2944
else
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}')
3146
fi
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
:
4458
else
4559
change_worktree

0 commit comments

Comments
 (0)