Skip to content

Commit 0dac0c7

Browse files
committed
feat: compgen -W option completion
Signed-off-by: wxiwnd <wxiwnd@outlook.com>
1 parent 3b8786d commit 0dac0c7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scripts/bash_pinyin_completion

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@ _comp_compgen__call_builtin() {
126126
esac
127127
done
128128

129+
# Also check if -W option is used with ${files[@]} or similar array expansion
130+
# which is a common pattern for file completion
131+
if [[ "$is_file_completion" == false ]]; then
132+
local i=0
133+
while [[ $i -lt ${#compgen_args[@]} ]]; do
134+
if [[ "${compgen_args[$i]}" == "-W" ]]; then
135+
local next_idx=$((i + 1))
136+
if [[ $next_idx -lt ${#compgen_args[@]} ]]; then
137+
local word_arg="${compgen_args[$next_idx]}"
138+
# Check if it contains ${files or similar array patterns
139+
if [[ "$word_arg" == *'${files'* ]] || [[ "$word_arg" == *'${toks'* ]] || [[ "$word_arg" == *'$files'* ]] || [[ "$word_arg" == *'$toks'* ]]; then
140+
is_file_completion=true
141+
break
142+
fi
143+
fi
144+
fi
145+
((i++))
146+
done
147+
fi
148+
129149
# If this looks like file completion, add pinyin matches
130150
if [[ "$is_file_completion" == true ]]; then
131151
_add_completion "$@"

0 commit comments

Comments
 (0)