Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
yankeexe committed Apr 9, 2021
0 parents commit f1422b5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Yankee Maharjan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Git worktree switcher :octocat:
Switch between git worktrees with ease. :zap:

<img src = "https://i.imgur.com/RYuBJnE.gif" width="700" alt="demo of switching between git worktrees" />

## Installation

Make the script executable.

```bash
$ chmod +x wt
```

Copy the binary to any directory in your `$PATH`

```bash
$ sudo cp wt /usr/local/bin
```

## Usage
Switch between worktrees.
You can do a text search to change to the worktree directory.

```bash
$ wt <worktree-name/search-term>: search for worktree names and change directory.
```

> <details><summary><strong>Demo</strong></summary>
> <img src = "https://i.imgur.com/RYuBJnE.gif" width="700" alt="demo of switching between git worktrees" />
</details>

List out all the worktrees.

```bash
wt list: list out all the git worktrees.
```

```bash
wt help: show this help message.
```
46 changes: 46 additions & 0 deletions wt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Switch between git worktrees with ease.

args=("$@")

# show worktree list
worktree_list() {
git worktree list
}

help_message(){
echo -e "wt lets you quickly switch between your git worktrees.\n"
echo "Usage:"
echo -e "\twt list: list out all the git worktrees."
echo -e "\twt help: shows this help message."
echo -e "\twt <worktree-name/search-term>: search for worktree names and change to that directory."
}

# If the first argument is "list", show worktree list,
# if it is "help", then show the help message,
# 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
else
directory=$(git worktree list | awk '/'"${args[0]}"'/ {print $1}')
fi

# Change worktree based on user argument.
change_worktree() {
echo Changing to worktree at: $directory
cd $directory
exec $(echo $SHELL)
}

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

0 comments on commit f1422b5

Please sign in to comment.