mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "36ea20b550ed12036085e72c6828a11b608b8581" and "cd06c61195a1d76df71eee806c41db9ef379ea5b" have entirely different histories.
36ea20b550
...
cd06c61195
|
@ -18,9 +18,10 @@ 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)
|
||||||
|
|
||||||
|
@ -36,10 +37,3 @@ 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,15 +47,9 @@ 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
|
||||||
if recursive {
|
os.Mkdir(strings.TrimSpace(dirname), 0744)
|
||||||
os.MkdirAll(path, 0744)
|
|
||||||
} else {
|
|
||||||
os.Mkdir(path, 0744)
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
4
lua.go
4
lua.go
|
@ -48,9 +48,7 @@ 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,12 +44,11 @@ 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', "Force Hilbish to be a login shell")
|
getopt.BoolLong("login", 'l', "Makes Hilbish act like 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")
|
||||||
|
|
||||||
|
@ -58,11 +57,6 @@ 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,12 +33,11 @@ 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
|
||||||
|
@ -121,8 +120,7 @@ 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])
|
||||||
cmdArgs, _ := splitInput(argstring)
|
args[0] = alias
|
||||||
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