Skip to content

Commit

Permalink
Add bash autocompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
yankeexe committed Jan 22, 2022
1 parent d214d90 commit 14cb73e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ Copy the executable to any directory in your `$PATH`
$ sudo cp wt /usr/local/bin
```

### Tab Completion
:warning: Only **bash** completion is available for now.

```bash
sudo cp wt_completion.bash /etc/bash_completion.d
```

```bash
wt <TAB> <TAB>

# OR

wt <completion-characters> <TAB>
```

## Usage
Switch between worktrees.
You can do a text search to change to the worktree directory.
Expand Down Expand Up @@ -48,4 +63,4 @@ Update to the latest release

```bash
$ wt update
```
```
21 changes: 21 additions & 0 deletions wt_completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

_wt() {
local cur opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
list="$(wt list | awk '{ print $1; }' | tr "\n" " ")"
opts=""

for item in $list
do
opts+="$(basename "$item") "
done

if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )
fi
}

complete -F _wt wt

0 comments on commit 14cb73e

Please sign in to comment.