mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	Compare commits
	
		
			20 Commits
		
	
	
		
			75d7c6acc6
			...
			6bb2a2f8c8
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					6bb2a2f8c8 | ||
| 
						 | 
					8242e0bfc9 | ||
| 
						 | 
					69883c6b73 | ||
| 
						 | 
					4d38b913f1 | ||
| 
						 | 
					32dea836d5 | ||
| 
						 | 
					6e3f1e1b97 | ||
| 
						 | 
					c43aab6a60 | ||
| 
						 | 
					9934ba417f | ||
| 
						 | 
					a75100d15d | ||
| 
						 | 
					60b1b50bb3 | ||
| 
						 | 
					f00063beaa | ||
| 
						 | 
					7f8d8db53e | ||
| 
						 | 
					38f1d62598 | ||
| 
						 | 
					e580112e1b | ||
| 
						 | 
					d2a44c70c0 | ||
| 
						 | 
					447775f8c4 | ||
| 
						 | 
					338b45227c | ||
| 
						 | 
					80029cfff3 | ||
| 
						 | 
					d653a9c349 | ||
| 
						 | 
					9b3f8e818c | 
							
								
								
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
[submodule "libs/lunacolors"]
 | 
			
		||||
	path = libs/lunacolors
 | 
			
		||||
	url = https://github.com/Hilbis/Lunacolors
 | 
			
		||||
@ -1,16 +1,15 @@
 | 
			
		||||
-- Default Hilbish config
 | 
			
		||||
ansikit = require 'ansikit'
 | 
			
		||||
lunacolors = require 'lunacolors'
 | 
			
		||||
bait = require 'bait'
 | 
			
		||||
 | 
			
		||||
function doPrompt(fail)
 | 
			
		||||
	prompt(ansikit.format(
 | 
			
		||||
		'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆{reset} '
 | 
			
		||||
	prompt(lunacolors.format(
 | 
			
		||||
		'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆ '
 | 
			
		||||
	))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
print(ansikit.format('Welcome to {magenta}Hilbish{reset}, {cyan}' ..
 | 
			
		||||
os.getenv 'USER' .. '{reset}.\n' ..
 | 
			
		||||
'The nice lil shell for {blue}Lua{reset} fanatics!\n'))
 | 
			
		||||
print(lunacolors.format('Welcome to {magenta}Hilbish{reset}, {cyan}' .. _user .. 
 | 
			
		||||
'{reset}.\n' .. 'The nice lil shell for {blue}Lua{reset} fanatics!\n'))
 | 
			
		||||
 | 
			
		||||
doPrompt()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -52,7 +52,7 @@ sudo zypper install readline-devel
 | 
			
		||||
 | 
			
		||||
### Install
 | 
			
		||||
```sh
 | 
			
		||||
git clone https://github.com/Hilbis/Hilbish
 | 
			
		||||
git clone --recursive https://github.com/Hilbis/Hilbish
 | 
			
		||||
cd Hilbish
 | 
			
		||||
make build
 | 
			
		||||
sudo make install
 | 
			
		||||
@ -80,6 +80,7 @@ Make sure to read [CONTRIBUTING.md](CONTRIBUTING.md) before getting started.
 | 
			
		||||
 | 
			
		||||
### Special Thanks To
 | 
			
		||||
Everyone here who has contributed:
 | 
			
		||||
 | 
			
		||||
<a href="https://github.com/Hilbis/Hilbish/graphs/contributors">
 | 
			
		||||
  <img src="https://contrib.rocks/image?repo=Hilbis/Hilbish" />
 | 
			
		||||
</a>
 | 
			
		||||
 | 
			
		||||
@ -29,8 +29,8 @@ func (c *Commander) Loader(L *lua.LState) int {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Commander) register(L *lua.LState) int {
 | 
			
		||||
	cmdName := L.ToString(1)
 | 
			
		||||
	cmd := L.ToFunction(2)
 | 
			
		||||
	cmdName := L.CheckString(1)
 | 
			
		||||
	cmd := L.CheckFunction(2)
 | 
			
		||||
 | 
			
		||||
	c.Events.Emit("commandRegister", cmdName, cmd)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -4,8 +4,8 @@ import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	lua "github.com/yuin/gopher-lua"
 | 
			
		||||
	luar "layeh.com/gopher-luar"
 | 
			
		||||
	"github.com/yuin/gopher-lua"
 | 
			
		||||
	"layeh.com/gopher-luar"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Loader(L *lua.LState) int {
 | 
			
		||||
@ -27,7 +27,7 @@ var exports = map[string]lua.LGFunction{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func cd(L *lua.LState) int {
 | 
			
		||||
	path := L.ToString(1)
 | 
			
		||||
	path := L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	err := os.Chdir(strings.TrimSpace(path))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@ -41,7 +41,7 @@ func cd(L *lua.LState) int {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func mkdir(L *lua.LState) int {
 | 
			
		||||
	dirname := L.ToString(1)
 | 
			
		||||
	dirname := L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	// TODO: handle error here
 | 
			
		||||
	os.Mkdir(strings.TrimSpace(dirname), 0744)
 | 
			
		||||
@ -50,7 +50,7 @@ func mkdir(L *lua.LState) int {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func stat(L *lua.LState) int {
 | 
			
		||||
	path := L.ToString(1)
 | 
			
		||||
	path := L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	// TODO: handle error here
 | 
			
		||||
	pathinfo, _ := os.Stat(path)
 | 
			
		||||
 | 
			
		||||
@ -61,49 +61,6 @@ ansikit.cursorUp = function(y)
 | 
			
		||||
	return ansikit.printCSI(y, 'A')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
ansikit.format = function(text)
 | 
			
		||||
	local colors = {
 | 
			
		||||
		-- TODO: write codes manually instead of using functions
 | 
			
		||||
		-- less function calls = faster ????????
 | 
			
		||||
		reset = {'{reset}', ansikit.getCSI(0)},
 | 
			
		||||
		bold = {'{bold}', ansikit.getCSI(1)},
 | 
			
		||||
		dim = {'{dim}', ansikit.getCSI(2)},
 | 
			
		||||
		italic = {'{italic}', ansikit.getCSI(3)},
 | 
			
		||||
		underline = {'{underline}', ansikit.getCSI(4)},
 | 
			
		||||
		invert = {'{invert}', ansikit.getCSI(7)},
 | 
			
		||||
		bold_off = {'{bold-off}', ansikit.getCSI(22)},
 | 
			
		||||
		underline_off = {'{underline-off}', ansikit.getCSI(24)},
 | 
			
		||||
		black = {'{black}', ansikit.getCSI(30)},
 | 
			
		||||
		red = {'{red}', ansikit.getCSI(31)},
 | 
			
		||||
		green = {'{green}', ansikit.getCSI(32)},
 | 
			
		||||
		yellow = {'{yellow}', ansikit.getCSI(33)},
 | 
			
		||||
		blue = {'{blue}', ansikit.getCSI(34)},
 | 
			
		||||
		magenta = {'{magenta}', ansikit.getCSI(35)},
 | 
			
		||||
		cyan = {'{cyan}', ansikit.getCSI(36)},
 | 
			
		||||
		white = {'{white}', ansikit.getCSI(37)},
 | 
			
		||||
		red_bg = {'{red-bg}', ansikit.getCSI(41)},
 | 
			
		||||
		green_bg = {'{green-bg}', ansikit.getCSI(42)},
 | 
			
		||||
		yellow_bg = {'{green-bg}', ansikit.getCSI(43)},
 | 
			
		||||
		blue_bg = {'{blue-bg}', ansikit.getCSI(44)},
 | 
			
		||||
		magenta_bg = {'{magenta-bg}', ansikit.getCSI(45)},
 | 
			
		||||
		cyan_bg = {'{cyan-bg}', ansikit.getCSI(46)},
 | 
			
		||||
		white_bg = {'{white-bg}', ansikit.getCSI(47)},
 | 
			
		||||
		gray = {'{gray}', ansikit.getCSI(90)},
 | 
			
		||||
		bright_red = {'{bright-red}', ansikit.getCSI(91)},
 | 
			
		||||
		bright_green = {'{bright-green}', ansikit.getCSI(92)},
 | 
			
		||||
		bright_yellow = {'{bright-yellow}', ansikit.getCSI(93)},
 | 
			
		||||
		bright_blue = {'{bright-blue}', ansikit.getCSI(94)},
 | 
			
		||||
		bright_magenta = {'{bright-magenta}', ansikit.getCSI(95)},
 | 
			
		||||
		bright_cyan = {'{bright-cyan}', ansikit.getCSI(96)}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for k, v in pairs(colors) do
 | 
			
		||||
		text = text:gsub(v[1], v[2])
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	return text
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
ansikit.getCode = function(code, terminate)
 | 
			
		||||
	return string.char(0x001b) .. code ..
 | 
			
		||||
	(terminate and string.char(0x001b) .. '\\' or '')
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								libs/lunacolors
									
									
									
									
									
										Submodule
									
								
							
							
								
								
								
								
								
								
									
									
								
							
						
						
									
										1
									
								
								libs/lunacolors
									
									
									
									
									
										Submodule
									
								
							@ -0,0 +1 @@
 | 
			
		||||
Subproject commit 004bca95d6e848f03e237c46127286f8f064bebc
 | 
			
		||||
							
								
								
									
										39
									
								
								lua.go
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								lua.go
									
									
									
									
									
								
							@ -2,10 +2,12 @@ package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"hilbish/golibs/bait"
 | 
			
		||||
	"hilbish/golibs/commander"
 | 
			
		||||
	"hilbish/golibs/fs"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/yuin/gopher-lua"
 | 
			
		||||
)
 | 
			
		||||
@ -17,12 +19,13 @@ prompt(ansikit.format(
 | 
			
		||||
))
 | 
			
		||||
`
 | 
			
		||||
 | 
			
		||||
func LuaInit(confpath string) {
 | 
			
		||||
func LuaInit() {
 | 
			
		||||
	l = lua.NewState()
 | 
			
		||||
 | 
			
		||||
	l.OpenLibs()
 | 
			
		||||
 | 
			
		||||
	l.SetGlobal("_ver", lua.LString(version))
 | 
			
		||||
	l.SetGlobal("_user", lua.LString(curuser.Username))
 | 
			
		||||
 | 
			
		||||
	l.SetGlobal("prompt", l.NewFunction(hshprompt))
 | 
			
		||||
	l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
 | 
			
		||||
@ -53,6 +56,7 @@ func LuaInit(confpath string) {
 | 
			
		||||
	l.DoString(`package.path = package.path
 | 
			
		||||
	.. ';./libs/?/init.lua;./?/init.lua;./?/?.lua'
 | 
			
		||||
	.. ';/usr/share/hilbish/libs/?/init.lua;'
 | 
			
		||||
	.. ';/usr/share/hilbish/libs/?/?.lua;'
 | 
			
		||||
	.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/init.lua;'
 | 
			
		||||
	.. os.getenv 'HOME'	.. '/.local/share/hilbish/libs/?/?.lua;'
 | 
			
		||||
	.. os.getenv 'HOME'	.. '/.local/share/hilbish/libs/?.lua'
 | 
			
		||||
@ -66,12 +70,12 @@ func LuaInit(confpath string) {
 | 
			
		||||
				"Missing preload file, builtins may be missing.")
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Run config
 | 
			
		||||
}
 | 
			
		||||
func RunConfig(confpath string) {
 | 
			
		||||
	if !interactive {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	err = l.DoFile(confpath)
 | 
			
		||||
	err := l.DoFile(confpath)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Fprintln(os.Stderr, err,
 | 
			
		||||
			"\nAn error has occured while loading your config! Falling back to minimal default config.\n")
 | 
			
		||||
@ -80,21 +84,35 @@ func LuaInit(confpath string) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func RunLogin() {
 | 
			
		||||
	if _, err := os.Stat(homedir + "/.hprofile.lua"); os.IsNotExist(err) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if !login {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	err := l.DoFile(homedir + "/.hprofile.lua")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Fprintln(os.Stderr, err,
 | 
			
		||||
			"\nAn error has occured while loading your login config!n")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hshprompt(L *lua.LState) int {
 | 
			
		||||
	prompt = L.ToString(1)
 | 
			
		||||
	prompt = L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hshmlprompt(L *lua.LState) int {
 | 
			
		||||
	multilinePrompt = L.ToString(1)
 | 
			
		||||
	multilinePrompt = L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hshalias(L *lua.LState) int {
 | 
			
		||||
	alias := L.ToString(1)
 | 
			
		||||
	source := L.ToString(2)
 | 
			
		||||
	alias := L.CheckString(1)
 | 
			
		||||
	source := L.CheckString(2)
 | 
			
		||||
 | 
			
		||||
	aliases[alias] = source
 | 
			
		||||
 | 
			
		||||
@ -102,7 +120,8 @@ func hshalias(L *lua.LState) int {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func hshappendPath(L *lua.LState) int {
 | 
			
		||||
	path := L.ToString(1)
 | 
			
		||||
	path := L.CheckString(1)
 | 
			
		||||
	path = strings.Replace(path, "~", curuser.HomeDir, 1)
 | 
			
		||||
 | 
			
		||||
	os.Setenv("PATH", os.Getenv("PATH") + ":" + path)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										33
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								main.go
									
									
									
									
									
								
							@ -4,9 +4,10 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"os/signal"
 | 
			
		||||
	"os/user"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
 | 
			
		||||
	"hilbish/golibs/bait"
 | 
			
		||||
 | 
			
		||||
@ -16,26 +17,29 @@ import (
 | 
			
		||||
	"golang.org/x/term"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const version = "0.4.0-dev.6"
 | 
			
		||||
const version = "0.4.0"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	l *lua.LState
 | 
			
		||||
 | 
			
		||||
	// User's prompt, this will get set when lua side is initialized
 | 
			
		||||
	prompt string
 | 
			
		||||
	prompt string // User's prompt, this will get set when lua side is initialized
 | 
			
		||||
	multilinePrompt = "> "
 | 
			
		||||
 | 
			
		||||
	commands = map[string]bool{}
 | 
			
		||||
	aliases = map[string]string{}
 | 
			
		||||
 | 
			
		||||
	hooks bait.Bait
 | 
			
		||||
	homedir string
 | 
			
		||||
	running bool
 | 
			
		||||
	curuser *user.User
 | 
			
		||||
 | 
			
		||||
	running bool // Is a command currently running
 | 
			
		||||
	hooks bait.Bait
 | 
			
		||||
	interactive bool
 | 
			
		||||
	login bool // Are we the login shell?
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	homedir, _ = os.UserHomeDir()
 | 
			
		||||
	curuser, _ = user.Current()
 | 
			
		||||
	defaultconfpath := homedir + "/.hilbishrc.lua"
 | 
			
		||||
 | 
			
		||||
//	parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers")
 | 
			
		||||
@ -49,6 +53,7 @@ func main() {
 | 
			
		||||
	_ = getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
 | 
			
		||||
 | 
			
		||||
	getopt.Parse()
 | 
			
		||||
	loginshflag := getopt.Lookup('l').Seen()
 | 
			
		||||
	interactiveflag := getopt.Lookup('i').Seen()
 | 
			
		||||
 | 
			
		||||
	if *cmdflag == "" || interactiveflag {
 | 
			
		||||
@ -59,6 +64,11 @@ func main() {
 | 
			
		||||
		interactive = false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// first arg, first character
 | 
			
		||||
	if loginshflag || os.Args[0][0] == '-' {
 | 
			
		||||
		login = true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if *verflag {
 | 
			
		||||
		fmt.Printf("Hilbish v%s\n", version)
 | 
			
		||||
		os.Exit(0)
 | 
			
		||||
@ -94,7 +104,9 @@ func main() {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	go HandleSignals()
 | 
			
		||||
	LuaInit(*configflag)
 | 
			
		||||
	LuaInit()
 | 
			
		||||
	RunLogin()
 | 
			
		||||
	RunConfig(*configflag)
 | 
			
		||||
 | 
			
		||||
	readline.Completer = readline.FilenameCompleter
 | 
			
		||||
	readline.LoadHistory(homedir + "/.hilbish-history")
 | 
			
		||||
@ -148,6 +160,7 @@ func main() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ContinuePrompt(prev string) (string, error) {
 | 
			
		||||
	hooks.Em.Emit("multiline", nil)
 | 
			
		||||
	cont, err := readline.String(multilinePrompt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		fmt.Println("")
 | 
			
		||||
@ -160,16 +173,16 @@ func ContinuePrompt(prev string) (string, error) {
 | 
			
		||||
 | 
			
		||||
// This semi cursed function formats our prompt (obviously)
 | 
			
		||||
func fmtPrompt() string {
 | 
			
		||||
	user, _ := user.Current()
 | 
			
		||||
	host, _ := os.Hostname()
 | 
			
		||||
	cwd, _ := os.Getwd()
 | 
			
		||||
 | 
			
		||||
	cwd = strings.Replace(cwd, user.HomeDir, "~", 1)
 | 
			
		||||
	cwd = strings.Replace(cwd, curuser.HomeDir, "~", 1)
 | 
			
		||||
 | 
			
		||||
	args := []string{
 | 
			
		||||
		"d", cwd,
 | 
			
		||||
		"D", filepath.Base(cwd),
 | 
			
		||||
		"h", host,
 | 
			
		||||
		"u", user.Username,
 | 
			
		||||
		"u", curuser.Username,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for i, v := range args {
 | 
			
		||||
 | 
			
		||||
@ -12,6 +12,8 @@ commander.register('cd', function (args)
 | 
			
		||||
		for i = 1, #args do
 | 
			
		||||
			path = path .. tostring(args[i]) .. ' '
 | 
			
		||||
		end
 | 
			
		||||
		path = path:gsub('$%$','\0'):gsub('${([%w_]+)}', os.getenv)
 | 
			
		||||
		:gsub('$([%w_]+)', os.getenv):gsub('%z','$')
 | 
			
		||||
 | 
			
		||||
		local ok, err = pcall(function() fs.cd(path) end)
 | 
			
		||||
		if not ok then
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user