mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	Compare commits
	
		
			14 Commits
		
	
	
		
			09a4cb4787
			...
			23f6986123
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 23f6986123 | ||
|  | 2d93f2ce4a | ||
|  | b1f2a36639 | ||
|  | 204d50d73c | ||
|  | 0987899144 | ||
|  | a9018a2740 | ||
|  | 5500baf5b6 | ||
|  | 60a0204958 | ||
|  | 8d92fc3b74 | ||
|  | 7326cb77c6 | ||
|  | 0d5c826f54 | ||
|  | 5dd7ce382a | ||
|  | 1d22e4cdc1 | ||
|  | 1234c780f8 | 
							
								
								
									
										1
									
								
								.github/semantic.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.github/semantic.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | |||||||
|  | titleAndCommits: true | ||||||
							
								
								
									
										2
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								TODO.md
									
									
									
									
									
								
							| @ -6,3 +6,5 @@ | |||||||
| - [ ] Readme badges | - [ ] Readme badges | ||||||
| - [x] Hooks | - [x] Hooks | ||||||
| - [x] Aliases | - [x] Aliases | ||||||
|  | - [ ] hlua (hilbish lua) - 100% lua in the hilbish interactive shell, cuz why not | ||||||
|  | - [ ] Petals (name of plugins) | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ package fs | |||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/yuin/gopher-lua" | 	"github.com/yuin/gopher-lua" | ||||||
| ) | ) | ||||||
| @ -13,6 +14,12 @@ func Loader(L *lua.LState) int { | |||||||
|     return 1 |     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{ | var exports = map[string]lua.LGFunction{ | ||||||
|     "cd": cd, |     "cd": cd, | ||||||
| } | } | ||||||
| @ -20,7 +27,13 @@ var exports = map[string]lua.LGFunction{ | |||||||
| func cd(L *lua.LState) int { | func cd(L *lua.LState) int { | ||||||
| 	path := L.ToString(1) | 	path := L.ToString(1) | ||||||
| 
 | 
 | ||||||
| 	os.Chdir(path) | 	err := os.Chdir(strings.TrimSpace(path)) | ||||||
|  | 	if err != nil { | ||||||
|  | 		switch err.(*os.PathError).Err.Error() { | ||||||
|  | 		case "no such file or directory": | ||||||
|  | 			LuaErr(L, 1) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	return 0 | 	return 0 | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										54
									
								
								lua.go
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								lua.go
									
									
									
									
									
								
							| @ -1,9 +1,63 @@ | |||||||
| package main | package main | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"fmt" | ||||||
|  | 	"os" | ||||||
|  | 	lfs "hilbish/golibs/fs" | ||||||
|  | 	cmds "hilbish/golibs/commander" | ||||||
|  | 	hooks "hilbish/golibs/bait" | ||||||
|  | 
 | ||||||
| 	"github.com/yuin/gopher-lua" | 	"github.com/yuin/gopher-lua" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | func LuaInit() { | ||||||
|  | 	l = lua.NewState() | ||||||
|  | 
 | ||||||
|  | 	l.OpenLibs() | ||||||
|  | 
 | ||||||
|  | 	l.SetGlobal("prompt", l.NewFunction(hshprompt)) | ||||||
|  | 	l.SetGlobal("alias", l.NewFunction(hshalias)) | ||||||
|  | 
 | ||||||
|  | 	// Add fs module to Lua | ||||||
|  | 	l.PreloadModule("fs", lfs.Loader) | ||||||
|  | 
 | ||||||
|  | 	commander := cmds.New() | ||||||
|  | 	// When a command from Lua is added, register it for use | ||||||
|  | 	commander.Events.On("commandRegister", | ||||||
|  | 	func (cmdName string, cmd *lua.LFunction) { | ||||||
|  | 		commands[cmdName] = true | ||||||
|  | 		l.SetField( | ||||||
|  | 			l.GetTable(l.GetGlobal("commanding"), | ||||||
|  | 			lua.LString("__commands")), | ||||||
|  | 			cmdName, | ||||||
|  | 			cmd) | ||||||
|  | 	}) | ||||||
|  | 
 | ||||||
|  | 	l.PreloadModule("commander", commander.Loader) | ||||||
|  | 
 | ||||||
|  | 	bait = hooks.New() | ||||||
|  | 	l.PreloadModule("bait", bait.Loader) | ||||||
|  | 
 | ||||||
|  | 	// Add more paths that Lua can require from | ||||||
|  | 	l.DoString("package.path = package.path .. ';./libs/?/init.lua;/usr/share/hilbish/libs/?/init.lua'") | ||||||
|  | 
 | ||||||
|  | 	err := l.DoFile("/usr/share/hilbish/preload.lua") | ||||||
|  | 	if err != nil { | ||||||
|  | 		err = l.DoFile("preload.lua") | ||||||
|  | 		if err != nil { | ||||||
|  | 			fmt.Fprintln(os.Stderr, | ||||||
|  | 			"Missing preload file, builtins may be missing.") | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	homedir, _ := os.UserHomeDir() | ||||||
|  | 	// Run config | ||||||
|  | 	err = l.DoFile(homedir + "/.hilbishrc.lua") | ||||||
|  | 	if err != nil { | ||||||
|  | 		panic(err) | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func hshprompt(L *lua.LState) int { | func hshprompt(L *lua.LState) int { | ||||||
| 	prompt = L.ToString(1) | 	prompt = L.ToString(1) | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										51
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								main.go
									
									
									
									
									
								
							| @ -10,8 +10,6 @@ import ( | |||||||
| 	"strings" | 	"strings" | ||||||
| 	"io" | 	"io" | ||||||
| 	"context" | 	"context" | ||||||
| 	lfs "hilbish/golibs/fs" |  | ||||||
| 	cmds "hilbish/golibs/commander" |  | ||||||
| 	hooks "hilbish/golibs/bait" | 	hooks "hilbish/golibs/bait" | ||||||
| 
 | 
 | ||||||
| 	"github.com/akamensky/argparse" | 	"github.com/akamensky/argparse" | ||||||
| @ -110,6 +108,7 @@ func main() { | |||||||
| 		if err == nil { | 		if err == nil { | ||||||
| 			// If it succeeds, add to history and prompt again | 			// If it succeeds, add to history and prompt again | ||||||
| 			readline.AddHistory(cmdString) | 			readline.AddHistory(cmdString) | ||||||
|  | 			bait.Em.Emit("command.success", nil) | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -304,51 +303,3 @@ func HandleSignals() { | |||||||
| 	}() | 	}() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func LuaInit() { |  | ||||||
| 	// TODO: Move to lua.go |  | ||||||
| 	l = lua.NewState() |  | ||||||
| 
 |  | ||||||
| 	l.OpenLibs() |  | ||||||
| 
 |  | ||||||
| 	l.SetGlobal("prompt", l.NewFunction(hshprompt)) |  | ||||||
| 	l.SetGlobal("alias", l.NewFunction(hshalias)) |  | ||||||
| 
 |  | ||||||
| 	// Add fs module to Lua |  | ||||||
| 	l.PreloadModule("fs", lfs.Loader) |  | ||||||
| 
 |  | ||||||
| 	commander := cmds.New() |  | ||||||
| 	// When a command from Lua is added, register it for use |  | ||||||
| 	commander.Events.On("commandRegister", |  | ||||||
| 	func (cmdName string, cmd *lua.LFunction) { |  | ||||||
| 		commands[cmdName] = true |  | ||||||
| 		l.SetField( |  | ||||||
| 			l.GetTable(l.GetGlobal("commanding"), |  | ||||||
| 			lua.LString("__commands")), |  | ||||||
| 			cmdName, |  | ||||||
| 			cmd) |  | ||||||
| 	}) |  | ||||||
| 
 |  | ||||||
| 	l.PreloadModule("commander", commander.Loader) |  | ||||||
| 
 |  | ||||||
| 	bait = hooks.New() |  | ||||||
| 	l.PreloadModule("bait", bait.Loader) |  | ||||||
| 
 |  | ||||||
| 	// Add more paths that Lua can require from |  | ||||||
| 	l.DoString("package.path = package.path .. ';./libs/?/init.lua;/usr/share/hilbish/libs/?/init.lua'") |  | ||||||
| 
 |  | ||||||
| 	err := l.DoFile("/usr/share/hilbish/preload.lua") |  | ||||||
| 	if err != nil { |  | ||||||
| 		err = l.DoFile("preload.lua") |  | ||||||
| 		if err != nil { |  | ||||||
| 			fmt.Fprintln(os.Stderr, |  | ||||||
| 			"Missing preload file, builtins may be missing.") |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	homedir, _ := os.UserHomeDir() |  | ||||||
| 	// Run config |  | ||||||
| 	err = l.DoFile(homedir + "/.hilbishrc.lua") |  | ||||||
| 	if err != nil { |  | ||||||
| 		panic(err) |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  | |||||||
							
								
								
									
										22
									
								
								preload.lua
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								preload.lua
									
									
									
									
									
								
							| @ -3,9 +3,25 @@ | |||||||
| 
 | 
 | ||||||
| local fs = require 'fs' | local fs = require 'fs' | ||||||
| local commander = require 'commander' | local commander = require 'commander' | ||||||
|  | local bait = require 'bait' | ||||||
| 
 | 
 | ||||||
| commander.register('cd', function (path) | commander.register('cd', function (args) | ||||||
| 	if #path == 1 then | 	bait.throw('cd', args) | ||||||
| 		fs.cd(path[1]) | 	if #args > 0 then | ||||||
|  | 		local path = '' | ||||||
|  | 		for i = 1, #args do | ||||||
|  | 			path = path .. tostring(args[i]) .. ' ' | ||||||
| 		end | 		end | ||||||
|  | 
 | ||||||
|  | 		local ok, err = pcall(function() fs.cd(path) end) | ||||||
|  | 		if not ok then | ||||||
|  | 			if err == 1 then | ||||||
|  | 				print('directory does not exist') | ||||||
|  | 			end | ||||||
|  | 			bait.throw('command.fail', nil) | ||||||
|  | 		else bait.throw('command.success', nil) end | ||||||
|  | 		return | ||||||
|  | 	end | ||||||
|  | 	fs.cd(os.getenv 'HOME') | ||||||
|  | 	bait.throw('command.success', nil) | ||||||
| end) | end) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user