File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change 3
3
# AUTOCOMPLETION FOR ZSH
4
4
# Reference: https://zsh.sourceforge.io/Doc/Release/Completion-Widgets.html
5
5
6
- # wt list: list all the available worktrees
7
- # | awk '{ print $1; }': grab the first column of the output
8
- # | tr "\n" " ": replace line break character with space to put the worktrees on single line
9
- # separated by space
10
-
11
- list="$(wt list | awk '{ print $1; }' | tr "\n" " ")"
6
+ # Declare an associative array named `opts`
12
7
declare -A opts
13
8
9
+ # Split the worktree names into an array, line-by-line.
10
+ list=("${(@f)$(wt names)}")
11
+
14
12
# Create associative array with key same as its value
15
13
# Completion keywords are taken as keys of arrays and the possible matches are their values
16
- # shwordsplit: iterate over a string separated by space (like sh/bash)
17
- setopt shwordsplit
18
14
for item in $list; do
19
- base="$(basename -- "$item")"
20
- opts+=(["$base"]="$base")
15
+ # Escape every element's special characters
16
+ item=$(printf '%q' "$item")
17
+ opts+=(["$item"]="$item")
21
18
done
22
- unsetopt shwordsplit
23
19
20
+ # Add the keys of `opts` as completion options for the `wt` command.
21
+ # `-Q` quotes the completion options.
22
+ # `-a` specifies that the options are taken from an associative array.
24
23
compadd -Qa opts
You can’t perform that action at this time.
0 commit comments