fix: completions not working with aliases commands (resolves #82)

dev
TorchedSammy 2021-11-22 18:01:59 -05:00
parent 52a6eb2125
commit 812de48558
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 16 additions and 3 deletions

19
rl.go
View File

@ -8,9 +8,10 @@ package main
// this is normal readline
import (
"fmt"
"os"
"path/filepath"
"strings"
"os"
"github.com/Rosettea/readline"
"github.com/yuin/gopher-lua"
@ -25,12 +26,24 @@ func NewLineReader(prompt string) *LineReader {
var completions []string
// trim whitespace from ctx
ctx = strings.TrimLeft(ctx, " ")
fields := strings.Split(ctx, " ")
fields, ctx := splitInput(ctx)
if len(fields) == 0 {
return nil
}
for aliases[fields[0]] != "" {
alias := aliases[fields[0]]
ctx = alias + strings.TrimPrefix(ctx, fields[0])
fields = strings.Split(ctx, " ")
if aliases[fields[0]] == alias {
break
}
if aliases[fields[0]] != "" {
continue
}
}
if len(fields) == 1 {
prefixes := []string{"./", "../"}
for _, prefix := range prefixes {