mirror of https://github.com/Hilbis/Hilbish
Compare commits
8 Commits
cd06c61195
...
36ea20b550
Author | SHA1 | Date |
---|---|---|
sammyette | 36ea20b550 | |
sammyette | 81f7b77b8b | |
sammyette | e6c4c32bd7 | |
sammyette | b974ada64e | |
sammyette | 7e5f9e9541 | |
sammyette | a413b28f2a | |
sammyette | 26eee56c8b | |
sammyette | fb04322844 |
|
@ -18,10 +18,9 @@ func New() Commander {
|
||||||
func (c *Commander) Loader(L *lua.LState) int {
|
func (c *Commander) Loader(L *lua.LState) int {
|
||||||
var exports = map[string]lua.LGFunction{
|
var exports = map[string]lua.LGFunction{
|
||||||
"register": c.register,
|
"register": c.register,
|
||||||
|
"deregister": c.deregister,
|
||||||
}
|
}
|
||||||
mod := L.SetFuncs(L.NewTable(), exports)
|
mod := L.SetFuncs(L.NewTable(), exports)
|
||||||
L.SetGlobal("commanding", &lua.LTable{})
|
|
||||||
L.SetField(L.GetGlobal("commanding"), "__commands", L.NewTable())
|
|
||||||
|
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
|
|
||||||
|
@ -37,3 +36,10 @@ func (c *Commander) register(L *lua.LState) int {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Commander) deregister(L *lua.LState) int {
|
||||||
|
cmdName := L.CheckString(1)
|
||||||
|
|
||||||
|
c.Events.Emit("commandDeregister", cmdName)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
|
@ -47,9 +47,15 @@ func cd(L *lua.LState) int {
|
||||||
|
|
||||||
func mkdir(L *lua.LState) int {
|
func mkdir(L *lua.LState) int {
|
||||||
dirname := L.CheckString(1)
|
dirname := L.CheckString(1)
|
||||||
|
recursive := L.ToBool(2)
|
||||||
|
path := strings.TrimSpace(dirname)
|
||||||
|
|
||||||
// TODO: handle error here
|
// TODO: handle error here
|
||||||
os.Mkdir(strings.TrimSpace(dirname), 0744)
|
if recursive {
|
||||||
|
os.MkdirAll(path, 0744)
|
||||||
|
} else {
|
||||||
|
os.Mkdir(path, 0744)
|
||||||
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
4
lua.go
4
lua.go
|
@ -48,7 +48,9 @@ func LuaInit() {
|
||||||
cmds.Events.On("commandRegister", func(cmdName string, cmd *lua.LFunction) {
|
cmds.Events.On("commandRegister", func(cmdName string, cmd *lua.LFunction) {
|
||||||
commands[cmdName] = cmd
|
commands[cmdName] = cmd
|
||||||
})
|
})
|
||||||
|
cmds.Events.On("commandDeregister", func(cmdName string) {
|
||||||
|
delete(commands, cmdName)
|
||||||
|
})
|
||||||
l.PreloadModule("commander", cmds.Loader)
|
l.PreloadModule("commander", cmds.Loader)
|
||||||
|
|
||||||
hooks = bait.New()
|
hooks = bait.New()
|
||||||
|
|
8
main.go
8
main.go
|
@ -44,11 +44,12 @@ func main() {
|
||||||
defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua")
|
defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags")
|
||||||
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
|
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
|
||||||
setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path")
|
setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path")
|
||||||
cmdflag := getopt.StringLong("command", 'c', "", "Executes a command on startup")
|
cmdflag := getopt.StringLong("command", 'c', "", "Executes a command on startup")
|
||||||
configflag := getopt.StringLong("config", 'C', defaultConfPath, "Sets the path to Hilbish's config")
|
configflag := getopt.StringLong("config", 'C', defaultConfPath, "Sets the path to Hilbish's config")
|
||||||
getopt.BoolLong("login", 'l', "Makes Hilbish act like a login shell")
|
getopt.BoolLong("login", 'l', "Force Hilbish to be a login shell")
|
||||||
getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
|
getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
|
||||||
getopt.BoolLong("noexec", 'n', "Don't execute and only report Lua syntax errors")
|
getopt.BoolLong("noexec", 'n', "Don't execute and only report Lua syntax errors")
|
||||||
|
|
||||||
|
@ -57,6 +58,11 @@ func main() {
|
||||||
interactiveflag := getopt.Lookup('i').Seen()
|
interactiveflag := getopt.Lookup('i').Seen()
|
||||||
noexecflag := getopt.Lookup('n').Seen()
|
noexecflag := getopt.Lookup('n').Seen()
|
||||||
|
|
||||||
|
if *helpflag {
|
||||||
|
getopt.PrintUsage(os.Stdout)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if *cmdflag == "" || interactiveflag {
|
if *cmdflag == "" || interactiveflag {
|
||||||
interactive = true
|
interactive = true
|
||||||
}
|
}
|
||||||
|
|
8
shell.go
8
shell.go
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
// "github.com/bobappleyard/readline"
|
// "github.com/bobappleyard/readline"
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
"github.com/yuin/gopher-lua/parse"
|
// "github.com/yuin/gopher-lua/parse"
|
||||||
"layeh.com/gopher-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"
|
||||||
|
@ -33,11 +33,12 @@ func RunInput(input string) {
|
||||||
fn, err := l.LoadString(cmdString)
|
fn, err := l.LoadString(cmdString)
|
||||||
if err != nil && noexecute {
|
if err != nil && noexecute {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
if lerr, ok := err.(*lua.ApiError); ok {
|
/* if lerr, ok := err.(*lua.ApiError); ok {
|
||||||
if perr, ok := lerr.Cause.(*parse.Error); ok {
|
if perr, ok := lerr.Cause.(*parse.Error); ok {
|
||||||
print(perr.Pos.Line == parse.EOF)
|
print(perr.Pos.Line == parse.EOF)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// And if there's no syntax errors and -n isnt provided, run
|
// And if there's no syntax errors and -n isnt provided, run
|
||||||
|
@ -120,7 +121,8 @@ func execCommand(cmd string) error {
|
||||||
if aliases[args[0]] != "" {
|
if aliases[args[0]] != "" {
|
||||||
alias := aliases[args[0]]
|
alias := aliases[args[0]]
|
||||||
argstring = alias + strings.TrimPrefix(argstring, args[0])
|
argstring = alias + strings.TrimPrefix(argstring, args[0])
|
||||||
args[0] = alias
|
cmdArgs, _ := splitInput(argstring)
|
||||||
|
args = cmdArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
// If command is defined in Lua then run it
|
// If command is defined in Lua then run it
|
||||||
|
|
Loading…
Reference in New Issue