Skip to content

Commit 2bb7822

Browse files
committed
Add ZSH autocompletion
1 parent 7766b91 commit 2bb7822

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,31 @@ 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.
21+
### Tab Autocompletion :zap:
2322

23+
**For Bash**
2424
```bash
25-
sudo cp wt_completion /etc/bash_completion.d
25+
sudo cp completions/wt_completion /etc/bash_completion.d
2626
```
2727

28+
**For ZSH**
29+
> Note: completion file for zsh has `_` prefix
30+
31+
32+
Find paths where you can store your completion
33+
```bash
34+
print -rl -- $fpath
35+
```
36+
37+
Copy completion script to one of that location and restart the shell.
38+
39+
```bash
40+
sudo cp completions/_wt_completion <one-of-$fpath>
41+
42+
exec zsh
43+
```
44+
---
45+
Tab autocompletion works for switching between your worktrees.
2846
```bash
2947
wt <TAB> <TAB>
3048

completions/_wt_completion

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#compdef wt
2+
3+
# AUTOCOMPLETION FOR ZSH
4+
5+
list="$(wt list | awk '{ print $1; }' | tr "\n" " ")"
6+
declare -A opts
7+
8+
setopt shwordsplit
9+
for item in $list
10+
do
11+
base="$(basename ${item} | xargs)"
12+
opts+=(["$base"]="$base")
13+
done
14+
unsetopt shwordsplit
15+
16+
compadd -Qa opts

wt_completion renamed to completions/wt_completion

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
# AUTOCOMPLETION FOR BASH
4+
35
_wt() {
46
local cur opts
57
COMPREPLY=()

0 commit comments

Comments
 (0)