From 1cc1c4490266091c6ad20273c10501facb88c60b Mon Sep 17 00:00:00 2001 From: sago35 Date: Tue, 20 Dec 2022 22:07:55 +0900 Subject: [PATCH] Add $TINYGOROOT to package completion source (#3) (bash only) --- autocmpl.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/autocmpl.go b/autocmpl.go index 9129505..d10bd66 100644 --- a/autocmpl.go +++ b/autocmpl.go @@ -90,9 +90,24 @@ _tinygo_autocmpl_bash_autocomplete() { COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" opts=$( tinygo-autocmpl %s -- ${COMP_WORDS[@]:1:$COMP_CWORD} ) + tinygoroot=$( tinygo env TINYGOROOT ) + if [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then + tinygoroot=$( cygpath --unix "${tinygoroot}" ) + fi + if [ "${opts}" = "" ]; then - compopt -o filenames - COMPREPLY=( $(compgen -f -- "${cur}" ) ) + case "${cur}" in + .*) + compopt -o filenames + COMPREPLY=( $(compgen -f -- "${cur}" ) ) + ;; + *) + compopt -o nospace + for j in $(compgen -f -- "${tinygoroot}/src/${cur}" ); do + COMPREPLY[k++]=${j#${tinygoroot}/src/} + done + ;; + esac else COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) fi