From 57d75273567f046c2d4eb7e3ed460175350ee59f Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Thu, 21 Apr 2022 22:16:04 -0400 Subject: [PATCH] fix: make hilbish.which work with aliases and commanders --- api.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/api.go b/api.go index 658494c..eb7cc44 100644 --- a/api.go +++ b/api.go @@ -529,18 +529,27 @@ func hlprependPath(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return c.Next(), nil } -// which(binName) -// Searches for an executable called `binName` in the directories of $PATH +// which(name) +// Checks if `name` is a valid command // --- @param binName string func hlwhich(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { if err := c.Check1Arg(); err != nil { return nil, err } - binName, err := c.StringArg(0) + name, err := c.StringArg(0) if err != nil { return nil, err } - path, err := exec.LookPath(binName) + + cmd := aliases.Resolve(name) + + // check for commander + if commands[cmd] != nil { + // they dont resolve to a path, so just send the cmd + return c.PushingNext1(t.Runtime, rt.StringValue(cmd)), nil + } + + path, err := exec.LookPath(cmd) if err != nil { return c.Next(), nil }