Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON files as candidates for Bash completion of --target. #4

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion autocmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,21 @@ _tinygo_autocmpl_bash_autocomplete() {
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
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
if [[ "${prev}" == "--target" && "${cur}" == */* ]]; then
compopt -o filenames
COMPREPLY=($(compgen -f -- "${cur}" | while read -r file; do
if [[ -d "$file" || "$file" == *.json ]]; then
echo "$file"
fi
done))
elif [ "${opts}" = "" ]; then
case "${cur}" in
.*)
compopt -o filenames
Expand Down Expand Up @@ -287,6 +295,12 @@ func completionBash(args []string) string {

if strings.HasPrefix(prev, "-") {
f := strings.TrimPrefix(prev, dash)

if f == "target" {
if strings.ContainsAny(cur, "/") {
return ""
}
}
if m, ok := flagCompleteMap[f]; ok {
for _, v := range m {
if v == cur {
Expand Down
Loading