Skip to content

Commit

Permalink
Feature: chanage to root worktree.
Browse files Browse the repository at this point in the history
Fix: multiline directory name capture error.
  • Loading branch information
yankeexe committed Apr 10, 2021
1 parent a5ee256 commit bd51780
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ You can do a text search to change to the worktree directory.
$ wt <worktree-name/search-term>
```

Go to root worktree directory

```bash
$ wt -
```

List out all the worktrees.

```bash
Expand Down
20 changes: 17 additions & 3 deletions wt
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,32 @@ help_message(){
echo -e "\twt <worktree-name/search-term>: search for worktree names and change to that directory."
}

goto_main_worktree() {
main_worktree=$(git worktree list | awk 'NR==1 {print $1}')

if [ -z $main_worktree ]; then
:
else
echo Changing to worktree at: $main_worktree
cd $main_worktree
exec $(echo $SHELL)
fi
}

# If the first argument is "list", show worktree list,
# if it is "help", then show the help message,
# if it is "-", go to the main working tree,
# else get worktree path based on user input.
if [ -z ${args[0]} ]; then
help_message
elif [ ${args[0]} == "list" ]; then
worktree_list
elif [ ${args[0]} == "help" ]; then
help_message
elif [ ${args[0]} == "-" ]; then
goto_main_worktree
else
directory=$(git worktree list | awk '/'"${args[0]}"'/ {print $1}')
directory=$(git worktree list | awk '/'"${args[0]}"'/ {print $1}' | awk 'NR==1 {print $1}')
fi

# Change worktree based on user argument.
Expand All @@ -38,8 +53,7 @@ change_worktree() {
}

# If directory variable is not empty then change worktree
if [ -z $directory ]
then
if [ -z $directory ]; then
:
else
change_worktree
Expand Down

0 comments on commit bd51780

Please sign in to comment.