From 1ff3ff854b4397da4f876bfb802ebb52964a1456 Mon Sep 17 00:00:00 2001 From: sammyette <38820196+TorchedSammy@users.noreply.github.com> Date: Sun, 16 May 2021 20:09:47 -0400 Subject: [PATCH] fix: add input to history before alias expansion since im stupid, normal commands that are aliased add the expanded version to the history, and not the alias itself. lua alias was added since im dumb and did `input` instead of `cmdString` so now, history is handled once, in main.go --- main.go | 8 ++++++++ shell.go | 13 ------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index c7d20d4..34ccd29 100644 --- a/main.go +++ b/main.go @@ -158,6 +158,7 @@ func main() { } } running = true + HandleHistory(input) RunInput(input) termwidth, _, err := term.GetSize(0) @@ -218,3 +219,10 @@ func HandleSignals() { } } } + +func HandleHistory(cmd string) { + readline.AddHistory(cmd) + readline.SaveHistory(homedir + "/.hilbish-history") + // TODO: load history again (history shared between sessions like this ye) +} + diff --git a/shell.go b/shell.go index fed3e25..d60f5b2 100644 --- a/shell.go +++ b/shell.go @@ -45,9 +45,6 @@ func RunInput(input string) { err = l.PCall(0, lua.MultRet, nil) } if err == nil { - // If it succeeds, add to history and prompt again - HandleHistory(input) - hooks.Em.Emit("command.exit", 0) return } @@ -75,9 +72,6 @@ func RunInput(input string) { fmt.Fprintln(os.Stderr, "Error in command:\n\n" + err.Error()) } - if cmdArgs[0] != "exit" { - HandleHistory(cmdString) - } hooks.Em.Emit("command.exit", exitcode) return } @@ -113,7 +107,6 @@ func RunInput(input string) { } else { hooks.Em.Emit("command.exit", 0) } - HandleHistory(cmdString) } // Run command in sh interpreter @@ -183,9 +176,3 @@ func splitInput(input string) ([]string, string) { return cmdArgs, cmdstr.String() } -func HandleHistory(cmd string) { - readline.AddHistory(cmd) - readline.SaveHistory(homedir + "/.hilbish-history") - // TODO: load history again (history shared between sessions like this ye) -} -