|
1 | 1 | # dotnet suggest shell complete script start
|
2 | 2 | _dotnet_bash_complete()
|
3 | 3 | {
|
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}") |
7 | 6 |
|
| 7 | + # filter suggestions by word to complete. |
| 8 | + local word="${COMP_WORDS[COMP_CWORD]}" |
8 | 9 | local IFS=$'\n'
|
9 |
| - local suggestions=($(compgen -W "$completions")) |
| 10 | + local suggestions=($(compgen -W "$completions" -- "$word")) |
10 | 11 |
|
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 |
18 | 16 |
|
19 |
| - COMPREPLY=("${suggestions[@]}") |
20 |
| - fi |
| 17 | + COMPREPLY=("${suggestions[@]}") |
21 | 18 | }
|
22 | 19 |
|
23 | 20 | _dotnet_bash_register_complete()
|
24 | 21 | {
|
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 |
27 | 26 | }
|
| 27 | + |
28 | 28 | _dotnet_bash_register_complete
|
29 |
| -export DOTNET_SUGGEST_SCRIPT_VERSION="1.0.2" |
| 29 | +export DOTNET_SUGGEST_SCRIPT_VERSION="1.0.3" |
30 | 30 | # dotnet suggest shell complete script end
|
0 commit comments