Skip to content

Commit

Permalink
Add JSON files as candidates for Bash completion of --target. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
sago35 authored Jan 24, 2025
1 parent 7bb81fb commit dec0390
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit dec0390

Please sign in to comment.