mirror of https://github.com/Hilbis/Hilbish
feat(wip): add appendpath
parent
bf11feb48b
commit
4476a96eec
|
@ -4,8 +4,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/yuin/gopher-lua"
|
lua "github.com/yuin/gopher-lua"
|
||||||
"layeh.com/gopher-luar"
|
luar "layeh.com/gopher-luar"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Loader(L *lua.LState) int {
|
func Loader(L *lua.LState) int {
|
||||||
|
@ -15,7 +15,6 @@ func Loader(L *lua.LState) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func LuaErr(L *lua.LState, code int) {
|
func LuaErr(L *lua.LState, code int) {
|
||||||
// TODO: Error with a table, with path and error code
|
// TODO: Error with a table, with path and error code
|
||||||
L.Error(lua.LNumber(code), 2)
|
L.Error(lua.LNumber(code), 2)
|
||||||
|
@ -25,6 +24,22 @@ var exports = map[string]lua.LGFunction{
|
||||||
"cd": cd,
|
"cd": cd,
|
||||||
"mkdir": mkdir,
|
"mkdir": mkdir,
|
||||||
"stat": stat,
|
"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 {
|
func cd(L *lua.LState) int {
|
||||||
|
|
6
lua.go
6
lua.go
|
@ -7,7 +7,7 @@ import (
|
||||||
lfs "hilbish/golibs/fs"
|
lfs "hilbish/golibs/fs"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/yuin/gopher-lua"
|
lua "github.com/yuin/gopher-lua"
|
||||||
)
|
)
|
||||||
|
|
||||||
var minimalconf = `
|
var minimalconf = `
|
||||||
|
@ -67,7 +67,9 @@ func LuaInit(confpath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run config
|
// Run config
|
||||||
if !interactive { return }
|
if !interactive {
|
||||||
|
return
|
||||||
|
}
|
||||||
err = l.DoFile(confpath)
|
err = l.DoFile(confpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err,
|
fmt.Fprintln(os.Stderr, err,
|
||||||
|
|
17
preload.lua
17
preload.lua
|
@ -5,6 +5,23 @@ local fs = require 'fs'
|
||||||
local commander = require 'commander'
|
local commander = require 'commander'
|
||||||
local bait = require 'bait'
|
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)
|
commander.register('cd', function (args)
|
||||||
bait.throw('cd', args)
|
bait.throw('cd', args)
|
||||||
if #args > 0 then
|
if #args > 0 then
|
||||||
|
|
8
shell.go
8
shell.go
|
@ -8,9 +8,9 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/yuin/gopher-lua"
|
|
||||||
"github.com/bobappleyard/readline"
|
"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/interp"
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
)
|
)
|
||||||
|
@ -167,7 +167,9 @@ func HandleHistory(cmd string) {
|
||||||
func StartMultiline(prev string, sb *strings.Builder) bool {
|
func StartMultiline(prev string, sb *strings.Builder) bool {
|
||||||
// sb fromt outside is passed so we can
|
// sb fromt outside is passed so we can
|
||||||
// save input from previous prompts
|
// save input from previous prompts
|
||||||
if sb.String() == "" { sb.WriteString(prev + " ") }
|
if sb.String() == "" {
|
||||||
|
sb.WriteString(prev + " ")
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Print(multilinePrompt)
|
fmt.Print(multilinePrompt)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue