mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "edcc1b39f09dbf9317d1cf4915208f6d1f7c3fdc" and "f0013096fdf025afdebcf1903540da4a1b748d71" have entirely different histories.
edcc1b39f0
...
f0013096fd
36
README.md
36
README.md
|
@ -41,21 +41,11 @@ Then click on the artifacts drop down, and download artifact for your platform,
|
||||||
like what is highlighted in the screenshot.
|
like what is highlighted in the screenshot.
|
||||||
<br><img src="https://modeus.is-inside.me/KJ0Puceb.png"><br>
|
<br><img src="https://modeus.is-inside.me/KJ0Puceb.png"><br>
|
||||||
|
|
||||||
### AUR
|
|
||||||
Arch Linux users can install Hilbish from the AUR.
|
|
||||||
```sh
|
|
||||||
yay -S hilbish
|
|
||||||
```
|
|
||||||
If you want the latest and greatest, you can install and compile from the latest git commit
|
|
||||||
```sh
|
|
||||||
yay -S hilbish-git
|
|
||||||
```
|
|
||||||
|
|
||||||
### Manual Build
|
### Manual Build
|
||||||
#### Prerequisites
|
#### Prerequisites
|
||||||
- [Go 1.16](https://go.dev)
|
- [Go 1.16](https://go.dev)
|
||||||
- GNU Readline
|
|
||||||
|
|
||||||
|
- GNU Readline
|
||||||
On Fedora, readline can be installed with:
|
On Fedora, readline can be installed with:
|
||||||
```
|
```
|
||||||
sudo dnf install readline-devel
|
sudo dnf install readline-devel
|
||||||
|
@ -71,11 +61,6 @@ On OpenSUSE, it can be installed with:
|
||||||
sudo zypper install readline-devel
|
sudo zypper install readline-devel
|
||||||
```
|
```
|
||||||
|
|
||||||
On Arch Linux, it can be installed with:
|
|
||||||
```
|
|
||||||
sudo pacman -S readline
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Build
|
#### Build
|
||||||
First, clone Hilbish:
|
First, clone Hilbish:
|
||||||
```sh
|
```sh
|
||||||
|
@ -89,16 +74,23 @@ And get dependencies and build:
|
||||||
```sh
|
```sh
|
||||||
go get -d all
|
go get -d all
|
||||||
make dev
|
make dev
|
||||||
|
# If you want to use latest stable release,
|
||||||
|
make build
|
||||||
|
# or want to use Hilbiline,
|
||||||
|
make hilbiline
|
||||||
```
|
```
|
||||||
|
|
||||||
If you `git checkout`'d the latest stable release, run
|
|
||||||
`make build` instead of `make dev`.
|
|
||||||
or want to experiment Hilbiline, instead run
|
|
||||||
`make hilbiline`
|
|
||||||
|
|
||||||
#### Install
|
#### Install
|
||||||
`sudo make install`
|
`sudo make install`
|
||||||
|
|
||||||
|
Alternatively, if you use Arch Linux, you can compile Hilbish with an **(unofficial)** AUR package:
|
||||||
|
```sh
|
||||||
|
yay -S hilbish
|
||||||
|
```
|
||||||
|
If you want the latest and greatest, you can install and compile from latest git commit:
|
||||||
|
```sh
|
||||||
|
yay -S hilbish-git
|
||||||
|
```
|
||||||
|
|
||||||
### Uninstall
|
### Uninstall
|
||||||
```sh
|
```sh
|
||||||
sudo make uninstall
|
sudo make uninstall
|
||||||
|
|
18
lua.go
18
lua.go
|
@ -16,8 +16,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var minimalconf = `
|
var minimalconf = `
|
||||||
lunacolors = require 'lunacolors'
|
ansikit = require 'ansikit'
|
||||||
prompt(lunacolors.format(
|
prompt(ansikit.format(
|
||||||
'{blue}%u {cyan}%d {green}∆{reset} '
|
'{blue}%u {cyan}%d {green}∆{reset} '
|
||||||
))
|
))
|
||||||
`
|
`
|
||||||
|
@ -42,7 +42,6 @@ func LuaInit() {
|
||||||
|
|
||||||
cmds := commander.New()
|
cmds := commander.New()
|
||||||
// When a command from Lua is added, register it for use
|
// When a command from Lua is added, register it for use
|
||||||
// TODO: maybe dont add command code to a lua table? insstead use a map
|
|
||||||
cmds.Events.On("commandRegister",
|
cmds.Events.On("commandRegister",
|
||||||
func(cmdName string, cmd *lua.LFunction) {
|
func(cmdName string, cmd *lua.LFunction) {
|
||||||
commands[cmdName] = true
|
commands[cmdName] = true
|
||||||
|
@ -59,11 +58,18 @@ func LuaInit() {
|
||||||
l.PreloadModule("bait", hooks.Loader)
|
l.PreloadModule("bait", hooks.Loader)
|
||||||
|
|
||||||
// Add more paths that Lua can require from
|
// Add more paths that Lua can require from
|
||||||
l.DoString("package.path = package.path .. " + requirePaths)
|
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'
|
||||||
|
`)
|
||||||
|
|
||||||
err := l.DoFile("preload.lua")
|
err := l.DoFile("preload.lua")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = l.DoFile(preloadPath)
|
err = l.DoFile("/usr/share/hilbish/preload.lua")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr,
|
fmt.Fprintln(os.Stderr,
|
||||||
"Missing preload file, builtins may be missing.")
|
"Missing preload file, builtins may be missing.")
|
||||||
|
@ -77,7 +83,7 @@ func RunConfig(confpath string) {
|
||||||
err := l.DoFile(confpath)
|
err := l.DoFile(confpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err,
|
fmt.Fprintln(os.Stderr, err,
|
||||||
"\nAn error has occured while loading your config! Falling back to minimal default config.")
|
"\nAn error has occured while loading your config! Falling back to minimal default config.\n")
|
||||||
|
|
||||||
l.DoString(minimalconf)
|
l.DoString(minimalconf)
|
||||||
}
|
}
|
||||||
|
|
34
main.go
34
main.go
|
@ -18,36 +18,37 @@ import (
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
version = "v0.4.0"
|
||||||
l *lua.LState
|
l *lua.LState
|
||||||
lr *LineReader
|
lr *LineReader
|
||||||
|
|
||||||
|
prompt string // User's prompt, this will get set when lua side is initialized
|
||||||
|
multilinePrompt = "> "
|
||||||
|
|
||||||
commands = map[string]bool{}
|
commands = map[string]bool{}
|
||||||
aliases = map[string]string{}
|
aliases = map[string]string{}
|
||||||
|
|
||||||
homedir string
|
homedir string
|
||||||
curuser *user.User
|
curuser *user.User
|
||||||
|
|
||||||
|
running bool // Is a command currently running
|
||||||
hooks bait.Bait
|
hooks bait.Bait
|
||||||
defaultConfPath string
|
interactive bool
|
||||||
|
login bool // Are we the login shell?
|
||||||
|
noexecute bool // Should we run Lua or only report syntax errors
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
homedir, _ = os.UserHomeDir()
|
homedir, _ = os.UserHomeDir()
|
||||||
curuser, _ = user.Current()
|
curuser, _ = user.Current()
|
||||||
|
defaultconfpath := homedir + "/.hilbishrc.lua"
|
||||||
if defaultConfDir == "" {
|
|
||||||
// we'll add *our* default if its empty (wont be if its changed comptime)
|
|
||||||
defaultConfPath = filepath.Join(homedir, "/.hilbishrc.lua")
|
|
||||||
} else {
|
|
||||||
// else do ~ substitution
|
|
||||||
defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua")
|
|
||||||
}
|
|
||||||
|
|
||||||
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', "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")
|
||||||
|
@ -89,21 +90,21 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If user's config doesn't exixt,
|
// If user's config doesn't exixt,
|
||||||
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) {
|
if _, err := os.Stat(defaultconfpath); os.IsNotExist(err) {
|
||||||
// Read default from current directory
|
// Read default from current directory
|
||||||
// (this is assuming the current dir is Hilbish's git)
|
// (this is assuming the current dir is Hilbish's git)
|
||||||
input, err := os.ReadFile(".hilbishrc.lua")
|
input, err := os.ReadFile(".hilbishrc.lua")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If it wasnt found, go to the real sample conf
|
// If it wasnt found, go to "real default"
|
||||||
input, err = os.ReadFile(sampleConfPath)
|
input, err = os.ReadFile("/usr/share/hilbish/.hilbishrc.lua")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("could not find .hilbishrc.lua or", sampleConfPath)
|
fmt.Println("could not find .hilbishrc.lua or /usr/share/hilbish/.hilbishrc.lua")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create it using either default config we found
|
// Create it using either default config we found
|
||||||
err = os.WriteFile(defaultConfPath, input, 0644)
|
err = os.WriteFile(homedir + "/.hilbishrc.lua", input, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If that fails, bail
|
// If that fails, bail
|
||||||
fmt.Println("Error creating config file")
|
fmt.Println("Error creating config file")
|
||||||
|
@ -226,7 +227,8 @@ func HandleSignals() {
|
||||||
|
|
||||||
for range c {
|
for range c {
|
||||||
if !running {
|
if !running {
|
||||||
lr.ClearInput()
|
//readline.ReplaceLine("", 0)
|
||||||
|
//readline.RefreshLine()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
21
preload.lua
21
preload.lua
|
@ -35,8 +35,7 @@ commander.register('cd', function (args)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
fs.cd(os.getenv 'HOME')
|
fs.cd(os.getenv 'HOME')
|
||||||
|
bait.throw('command.exit', 0)
|
||||||
return
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
commander.register('exit', function()
|
commander.register('exit', function()
|
||||||
|
@ -45,19 +44,19 @@ end)
|
||||||
|
|
||||||
do
|
do
|
||||||
local virt_G = { }
|
local virt_G = { }
|
||||||
|
|
||||||
setmetatable(_G, {
|
setmetatable(_G, {
|
||||||
__index = function (_, key)
|
__index = function (self, key)
|
||||||
local got_virt = virt_G[key]
|
local got_virt = virt_G[key]
|
||||||
if got_virt ~= nil then
|
if got_virt ~= nil then
|
||||||
return got_virt
|
return got_virt
|
||||||
end
|
end
|
||||||
|
|
||||||
virt_G[key] = os.getenv(key)
|
virt_G[key] = os.getenv(key)
|
||||||
return virt_G[key]
|
return virt_G[key]
|
||||||
end,
|
end,
|
||||||
|
|
||||||
__newindex = function (_, key, value)
|
__newindex = function (self, key, value)
|
||||||
if type(value) == 'string' then
|
if type(value) == 'string' then
|
||||||
os.setenv(key, value)
|
os.setenv(key, value)
|
||||||
virt_G[key] = value
|
virt_G[key] = value
|
||||||
|
@ -69,7 +68,7 @@ do
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
bait.catch('command.exit', function ()
|
bait.catch('command.exit', function ()
|
||||||
for key, value in pairs(virt_G) do
|
for key, value in pairs(virt_G) do
|
||||||
if type(value) == 'string' then
|
if type(value) == 'string' then
|
||||||
|
@ -83,15 +82,15 @@ end
|
||||||
function string.split(str, delimiter)
|
function string.split(str, delimiter)
|
||||||
local result = {}
|
local result = {}
|
||||||
local from = 1
|
local from = 1
|
||||||
|
|
||||||
local delim_from, delim_to = string.find(str, delimiter, from)
|
local delim_from, delim_to = string.find(str, delimiter, from)
|
||||||
|
|
||||||
while delim_from do
|
while delim_from do
|
||||||
table.insert(result, string.sub(str, from, delim_from - 1))
|
table.insert(result, string.sub(str, from, delim_from - 1))
|
||||||
from = delim_to + 1
|
from = delim_to + 1
|
||||||
delim_from, delim_to = string.find(str, delimiter, from)
|
delim_from, delim_to = string.find(str, delimiter, from)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(result, string.sub(str, from))
|
table.insert(result, string.sub(str, from))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
5
rl.go
5
rl.go
|
@ -34,8 +34,3 @@ func (lr *LineReader) AddHistory(cmd string) {
|
||||||
readline.SaveHistory(homedir + "/.hilbish-history")
|
readline.SaveHistory(homedir + "/.hilbish-history")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr *LineReader) ClearInput() {
|
|
||||||
readline.ReplaceLine("", 0)
|
|
||||||
readline.RefreshLine()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,3 @@ func (lr *LineReader) AddHistory(cmd string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lr *LineReader) ClearInput() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
13
shell.go
13
shell.go
|
@ -18,17 +18,6 @@ import (
|
||||||
func RunInput(input string) {
|
func RunInput(input string) {
|
||||||
cmdArgs, cmdString := splitInput(input)
|
cmdArgs, cmdString := splitInput(input)
|
||||||
|
|
||||||
// If alias was found, use command alias
|
|
||||||
for aliases[cmdArgs[0]] != "" {
|
|
||||||
alias := aliases[cmdArgs[0]]
|
|
||||||
cmdString = alias + strings.TrimPrefix(cmdString, cmdArgs[0])
|
|
||||||
cmdArgs, cmdString = splitInput(cmdString)
|
|
||||||
|
|
||||||
if aliases[cmdArgs[0]] != "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// First try to load input, essentially compiling to bytecode
|
// First try to load input, essentially compiling to bytecode
|
||||||
fn, err := l.LoadString(cmdString)
|
fn, err := l.LoadString(cmdString)
|
||||||
if err != nil && noexecute {
|
if err != nil && noexecute {
|
||||||
|
@ -160,7 +149,7 @@ func execCommand(cmd string) error {
|
||||||
return interp.NewExitStatus(127)
|
return interp.NewExitStatus(127)
|
||||||
}
|
}
|
||||||
|
|
||||||
return interp.DefaultExecHandler(2 * time.Second)(ctx, args)
|
return interp.DefaultExecHandler(2*time.Second)(ctx, args)
|
||||||
}
|
}
|
||||||
runner, _ := interp.New(
|
runner, _ := interp.New(
|
||||||
interp.StdIO(os.Stdin, os.Stdout, os.Stderr),
|
interp.StdIO(os.Stdin, os.Stdout, os.Stderr),
|
||||||
|
|
27
vars.go
27
vars.go
|
@ -1,27 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
// String vars that are free to be changed at compile time
|
|
||||||
var (
|
|
||||||
version = "v0.4.0"
|
|
||||||
requirePaths = `';./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'`
|
|
||||||
preloadPath = "/usr/share/hilbish/preload.lua"
|
|
||||||
defaultConfDir = "" // ~ will be substituted for home, path for user's default config
|
|
||||||
sampleConfPath = "/usr/share/hilbish/.hilbishrc.lua" // Path to default/sample config
|
|
||||||
|
|
||||||
prompt string // Prompt will always get changed anyway
|
|
||||||
multilinePrompt = "> "
|
|
||||||
)
|
|
||||||
|
|
||||||
// Flags
|
|
||||||
var (
|
|
||||||
running bool // Is a command currently running
|
|
||||||
interactive bool
|
|
||||||
login bool // Are we the login shell?
|
|
||||||
noexecute bool // Should we run Lua or only report syntax errors
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue