From 503d38e5c497ad8e15a06560c072d371555a849c Mon Sep 17 00:00:00 2001 From: verse91 Date: Sat, 11 Apr 2026 21:01:40 +0700 Subject: [PATCH] fix(spec): add token injection to resolve shell aliases --- commands/core/spec.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/commands/core/spec.go b/commands/core/spec.go index 57ffc11..277d8c8 100644 --- a/commands/core/spec.go +++ b/commands/core/spec.go @@ -73,10 +73,7 @@ func scanShellAliases() { if len(matches) == 3 { name := matches[1] target := matches[2] - fields := strings.Fields(target) - if len(fields) > 0 { - shellAliases[name] = fields[0] - } + shellAliases[name] = target } } } @@ -132,6 +129,20 @@ func Lookup(input string) []Suggestion { pathOnce.Do(scanExternalCommands) tokens := tokenize(input) + + // resolve shell alias (e.g. gca -> git commit -a) + if len(tokens) > 0 { + if target, ok := shellAliases[tokens[0]]; ok { + aliasTokens := tokenize(target) + // if the alias expansion ends with a space, tokenize might have an empty last token + // we should merge it carefully with tokens[1:] + if len(aliasTokens) > 0 && aliasTokens[len(aliasTokens)-1] == "" { + aliasTokens = aliasTokens[:len(aliasTokens)-1] + } + tokens = append(aliasTokens, tokens[1:]...) + } + } + if len(tokens) == 0 { return topLevelSuggestions(input) } @@ -142,17 +153,13 @@ func Lookup(input string) []Suggestion { } rootCmdName := tokens[0] - // resolve shell alias (e.g. g -> git) - if target, ok := shellAliases[rootCmdName]; ok { - rootCmdName = target - } - spec, exists := registry[rootCmdName] if !exists { // no spec found for this command, return nothing to avoid clutter return nil } + currentSubs := spec.Subcommands currentOpts := spec.Options currentGen := spec.Generator