mirror of https://github.com/Hilbis/Hilbish
refactor: handle history in lua
this also introduces a new opt: history if it is false, command history won't get addedlua-history
parent
9c91e6ee51
commit
a8475cfa67
6
exec.go
6
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)
|
||||
}
|
||||
|
|
5
main.go
5
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{}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue