diff --git a/exec.go b/exec.go index cc5016a..e1862ed 100644 --- a/exec.go +++ b/exec.go @@ -540,13 +540,9 @@ func splitInput(input string) ([]string, string) { } func cmdFinish(code uint8, cmdstr string, private bool) { - // if input has space at the beginning, dont put in history - if interactive && !private { - handleHistory(cmdstr) - } util.SetField(l, hshMod, "exitCode", rt.IntValue(int64(code)), "Exit code of last exected command") // using AsValue (to convert to lua type) on an interface which is an int // results in it being unknown in lua .... ???? // so we allow the hook handler to take lua runtime Values - hooks.Em.Emit("command.exit", rt.IntValue(int64(code)), cmdstr) + hooks.Em.Emit("command.exit", rt.IntValue(int64(code)), cmdstr, private) } diff --git a/main.go b/main.go index 99f333a..0664cc1 100644 --- a/main.go +++ b/main.go @@ -268,11 +268,6 @@ func fmtPrompt(prompt string) string { return nprompt } -func handleHistory(cmd string) { - lr.AddHistory(cmd) - // TODO: load history again (history shared between sessions like this ye) -} - func removeDupes(slice []string) []string { all := make(map[string]bool) newSlice := []string{} diff --git a/nature/init.lua b/nature/init.lua index df31d8d..845ade0 100644 --- a/nature/init.lua +++ b/nature/init.lua @@ -10,6 +10,7 @@ require 'nature.completions' require 'nature.opts' require 'nature.vim' require 'nature.runner' +require 'nature.history' local shlvl = tonumber(os.getenv 'SHLVL') if shlvl ~= nil then diff --git a/nature/opts/history.lua b/nature/opts/history.lua new file mode 100644 index 0000000..f7ab1d7 --- /dev/null +++ b/nature/opts/history.lua @@ -0,0 +1,5 @@ +local bait = require 'bait' + +bait.catch('command.exit', function(_, cmd, priv) + if not priv and hilbish.opts.history then hilbish.history.add(cmd) end +end) diff --git a/nature/opts/init.lua b/nature/opts/init.lua index 59d3cbd..3b39834 100644 --- a/nature/opts/init.lua +++ b/nature/opts/init.lua @@ -20,7 +20,8 @@ local function setupOpt(name, default) end local defaultOpts = { - autocd = false + autocd = false, + history = true } for optsName, default in pairs(defaultOpts) do