refactor: handle history in lua

this also introduces a new opt: history
if it is false, command history won't get added
lua-history
TorchedSammy 2022-07-09 16:49:56 -04:00
parent 9c91e6ee51
commit a8475cfa67
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
5 changed files with 9 additions and 11 deletions

View File

@ -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)
}

View File

@ -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{}

View File

@ -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

View File

@ -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)

View File

@ -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