Skip to content

Commit 7058640

Browse files
authored
dotnet-suggest-shim.bash: filter on word to complete. (#2187)
1 parent 1ad6f51 commit 7058640

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
# dotnet suggest shell complete script start
22
_dotnet_bash_complete()
33
{
4-
local fullpath=`type -p ${COMP_WORDS[0]}`
5-
local escaped_comp_line=$(echo "$COMP_LINE" | sed s/\"/'\\\"'/g)
6-
local completions=`dotnet-suggest get --executable "${fullpath}" --position ${COMP_POINT} -- "${escaped_comp_line}"`
4+
local fullpath=$(type -p "${COMP_WORDS[0]}")
5+
local completions=$(dotnet-suggest get --executable "${fullpath}" --position "${COMP_POINT}" -- "${COMP_LINE}")
76

7+
# filter suggestions by word to complete.
8+
local word="${COMP_WORDS[COMP_CWORD]}"
89
local IFS=$'\n'
9-
local suggestions=($(compgen -W "$completions"))
10+
local suggestions=($(compgen -W "$completions" -- "$word"))
1011

11-
if [ "${#suggestions[@]}" == "1" ]; then
12-
local number="${suggestions[0]/%\ */}"
13-
COMPREPLY=("$number")
14-
else
15-
for i in "${!suggestions[@]}"; do
16-
suggestions[$i]="$(printf '%*s' "-$COLUMNS" "${suggestions[$i]}")"
17-
done
12+
# format suggestions as shell input.
13+
for i in "${!suggestions[@]}"; do
14+
suggestions[i]="$(printf '%q' "${suggestions[$i]}")"
15+
done
1816

19-
COMPREPLY=("${suggestions[@]}")
20-
fi
17+
COMPREPLY=("${suggestions[@]}")
2118
}
2219

2320
_dotnet_bash_register_complete()
2421
{
25-
local IFS=$'\n'
26-
complete -F _dotnet_bash_complete `dotnet-suggest list`
22+
if command -v dotnet-suggest &>/dev/null; then
23+
local IFS=$'\n'
24+
complete -F _dotnet_bash_complete $(dotnet-suggest list)
25+
fi
2726
}
27+
2828
_dotnet_bash_register_complete
29-
export DOTNET_SUGGEST_SCRIPT_VERSION="1.0.2"
29+
export DOTNET_SUGGEST_SCRIPT_VERSION="1.0.3"
3030
# dotnet suggest shell complete script end

0 commit comments

Comments
 (0)