mirror of https://github.com/Hilbis/Hilbish
feat(wip): add appendpath
parent
bf11feb48b
commit
4476a96eec
|
@ -4,27 +4,42 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/yuin/gopher-lua"
|
||||
"layeh.com/gopher-luar"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
|
||||
L.Push(mod)
|
||||
return 1
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
func LuaErr(L *lua.LState, code int) {
|
||||
// TODO: Error with a table, with path and error code
|
||||
L.Error(lua.LNumber(code), 2)
|
||||
}
|
||||
|
||||
var exports = map[string]lua.LGFunction{
|
||||
"cd": cd,
|
||||
"mkdir": mkdir,
|
||||
"stat": stat,
|
||||
"cd": cd,
|
||||
"mkdir": mkdir,
|
||||
"stat": stat,
|
||||
"appendpath": appendpath,
|
||||
}
|
||||
|
||||
func appendpath(L *lua.LState) int {
|
||||
path := L.ToString(1)
|
||||
|
||||
os.Setenv("PATH", os.Getenv("PATH")+":"+path)
|
||||
// cmd := exec.Command("export PATH=" + os.Getenv("PATH") + ":" + path)
|
||||
// shell.execCommand("export PATH=" + os.Getenv("PATH") + ":" + path)
|
||||
|
||||
// fmt.Println(cmd.String())
|
||||
// err := cmd.Run()
|
||||
// if err != nil {
|
||||
// LuaErr(L, 1)
|
||||
// }
|
||||
return 0
|
||||
}
|
||||
|
||||
func cd(L *lua.LState) int {
|
||||
|
|
6
lua.go
6
lua.go
|
@ -7,7 +7,7 @@ import (
|
|||
lfs "hilbish/golibs/fs"
|
||||
"os"
|
||||
|
||||
"github.com/yuin/gopher-lua"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
var minimalconf = `
|
||||
|
@ -67,7 +67,9 @@ func LuaInit(confpath string) {
|
|||
}
|
||||
|
||||
// Run config
|
||||
if !interactive { return }
|
||||
if !interactive {
|
||||
return
|
||||
}
|
||||
err = l.DoFile(confpath)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err,
|
||||
|
|
17
preload.lua
17
preload.lua
|
@ -5,6 +5,23 @@ local fs = require 'fs'
|
|||
local commander = require 'commander'
|
||||
local bait = require 'bait'
|
||||
|
||||
commander.register('appendpath', function (args)
|
||||
bait.throw('appendpath', args)
|
||||
local path = ''
|
||||
for i = 1, #args do
|
||||
path = path .. tostring(args[i]) .. ':'
|
||||
end
|
||||
path = path:sub(1, -2)
|
||||
|
||||
local ok, err = pcall(function() fs.appendpath(path) end)
|
||||
if not ok then
|
||||
if err == 1 then
|
||||
print('failed to set path')
|
||||
end
|
||||
bait.throw('command.exit', err)
|
||||
else bait.throw('command.exit', 0) end
|
||||
end)
|
||||
|
||||
commander.register('cd', function (args)
|
||||
bait.throw('cd', args)
|
||||
if #args > 0 then
|
||||
|
|
8
shell.go
8
shell.go
|
@ -8,9 +8,9 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/yuin/gopher-lua"
|
||||
"github.com/bobappleyard/readline"
|
||||
"layeh.com/gopher-luar"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
"mvdan.cc/sh/v3/interp"
|
||||
"mvdan.cc/sh/v3/syntax"
|
||||
)
|
||||
|
@ -167,7 +167,9 @@ func HandleHistory(cmd string) {
|
|||
func StartMultiline(prev string, sb *strings.Builder) bool {
|
||||
// sb fromt outside is passed so we can
|
||||
// save input from previous prompts
|
||||
if sb.String() == "" { sb.WriteString(prev + " ") }
|
||||
if sb.String() == "" {
|
||||
sb.WriteString(prev + " ")
|
||||
}
|
||||
|
||||
fmt.Print(multilinePrompt)
|
||||
|
||||
|
|
Loading…
Reference in New Issue