Skip to content

Commit 14cb73e

Browse files
committed
Add bash autocompletion
1 parent d214d90 commit 14cb73e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ Copy the executable to any directory in your `$PATH`
1818
$ sudo cp wt /usr/local/bin
1919
```
2020

21+
### Tab Completion
22+
:warning: Only **bash** completion is available for now.
23+
24+
```bash
25+
sudo cp wt_completion.bash /etc/bash_completion.d
26+
```
27+
28+
```bash
29+
wt <TAB> <TAB>
30+
31+
# OR
32+
33+
wt <completion-characters> <TAB>
34+
```
35+
2136
## Usage
2237
Switch between worktrees.
2338
You can do a text search to change to the worktree directory.
@@ -48,4 +63,4 @@ Update to the latest release
4863

4964
```bash
5065
$ wt update
51-
```
66+
```

wt_completion

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
_wt() {
4+
local cur opts
5+
COMPREPLY=()
6+
cur="${COMP_WORDS[COMP_CWORD]}"
7+
list="$(wt list | awk '{ print $1; }' | tr "\n" " ")"
8+
opts=""
9+
10+
for item in $list
11+
do
12+
opts+="$(basename "$item") "
13+
done
14+
15+
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
16+
local cur=${COMP_WORDS[COMP_CWORD]}
17+
COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )
18+
fi
19+
}
20+
21+
complete -F _wt wt

0 commit comments

Comments
 (0)