From 812de485583119a3129f261bc4bca8a6917626ac Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Mon, 22 Nov 2021 18:01:59 -0500 Subject: [PATCH] fix: completions not working with aliases commands (resolves #82) --- rl.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/rl.go b/rl.go index 343cb02..b5f821e 100644 --- a/rl.go +++ b/rl.go @@ -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 {