mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	Compare commits
	
		
			8 Commits
		
	
	
		
			cd06c61195
			...
			36ea20b550
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					36ea20b550 | ||
| 
						 | 
					81f7b77b8b | ||
| 
						 | 
					e6c4c32bd7 | ||
| 
						 | 
					b974ada64e | ||
| 
						 | 
					7e5f9e9541 | ||
| 
						 | 
					a413b28f2a | ||
| 
						 | 
					26eee56c8b | ||
| 
						 | 
					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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user