mirror of https://github.com/Hilbis/Hilbish
Compare commits
9 Commits
70c2b91fca
...
a68b488828
Author | SHA1 | Date |
---|---|---|
sammyette | a68b488828 | |
sammyette | 41e5e3f789 | |
sammyette | 826b0789cb | |
sammyette | bfa3b55542 | |
sammyette | f7e66bb957 | |
sammyette | d7ab887234 | |
youkwhd | b24fc4a422 | |
sammyette | 0e4b95d9b9 | |
sammyette | eded38c7b5 |
|
@ -29,7 +29,7 @@ jobs:
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.18.8'
|
go-version: '1.22.2'
|
||||||
- name: Download Task
|
- name: Download Task
|
||||||
run: 'sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d'
|
run: 'sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d'
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|
|
@ -30,6 +30,9 @@ hilbish.run('wc -l', {
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix ansi attributes causing issues with text when cut off in greenhouse
|
- Fix ansi attributes causing issues with text when cut off in greenhouse
|
||||||
|
- `exec` command should return if no arg presented
|
||||||
|
- Commanders can now be cancelled by Ctrl-C and wont hang the shell anymore.
|
||||||
|
See [issue 198](https://github.com/Rosettea/Hilbish/issues/198).
|
||||||
|
|
||||||
## [2.2.3] - 2024-04-27
|
## [2.2.3] - 2024-04-27
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
> [!TIP]
|
||||||
|
> Check out [Hilbish: Midnight Edition](https://github.com/Rosettea/Hilbish/tree/midnight-edition) if you want to use C Lua, LuaJIT or anything related!
|
||||||
|
|
||||||
<img src="./assets/hilbish-logo-and-text.png" width=512><br>
|
<img src="./assets/hilbish-logo-and-text.png" width=512><br>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
🌓 The Moon-powered shell! A comfy and extensible shell for Lua fans! 🌺 ✨
|
🌓 The Moon-powered shell! A comfy and extensible shell for Lua fans! 🌺 ✨
|
||||||
|
@ -36,7 +39,7 @@ on the website for distributed binaries from GitHub or other package repositorie
|
||||||
Otherwise, continue reading for steps on compiling.
|
Otherwise, continue reading for steps on compiling.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
- [Go 1.17+](https://go.dev)
|
- [Go 1.22+](https://go.dev)
|
||||||
- [Task](https://taskfile.dev/installation/) (**Go on the hyperlink here to see Task's install method for your OS.**)
|
- [Task](https://taskfile.dev/installation/) (**Go on the hyperlink here to see Task's install method for your OS.**)
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
30
exec.go
30
exec.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -353,7 +354,34 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
|
||||||
sinks.Set(rt.StringValue("out"), rt.UserDataValue(stdout.ud))
|
sinks.Set(rt.StringValue("out"), rt.UserDataValue(stdout.ud))
|
||||||
sinks.Set(rt.StringValue("err"), rt.UserDataValue(stderr.ud))
|
sinks.Set(rt.StringValue("err"), rt.UserDataValue(stderr.ud))
|
||||||
|
|
||||||
luaexitcode, err := rt.Call1(l.MainThread(), rt.FunctionValue(cmd), rt.TableValue(luacmdArgs), rt.TableValue(sinks))
|
t := rt.NewThread(l)
|
||||||
|
sig := make(chan os.Signal)
|
||||||
|
exit := make(chan bool)
|
||||||
|
|
||||||
|
luaexitcode := rt.IntValue(63)
|
||||||
|
var err error
|
||||||
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
exit <- true
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
signal.Notify(sig, os.Interrupt)
|
||||||
|
select {
|
||||||
|
case <-sig:
|
||||||
|
t.KillContext()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
luaexitcode, err = rt.Call1(t, rt.FunctionValue(cmd), rt.TableValue(luacmdArgs), rt.TableValue(sinks))
|
||||||
|
exit <- true
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-exit
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "Error in command:\n" + err.Error())
|
fmt.Fprintln(os.Stderr, "Error in command:\n" + err.Error())
|
||||||
return interp.NewExitStatus(1)
|
return interp.NewExitStatus(1)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build linux darwin
|
//go:build unix
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build windows
|
//go:build windows
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build windows
|
//go:build windows
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build darwin linux
|
//go:build unix
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build windows
|
//go:build windows
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
9
main.go
9
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -115,7 +116,13 @@ func main() {
|
||||||
|
|
||||||
// Set $SHELL if the user wants to
|
// Set $SHELL if the user wants to
|
||||||
if *setshflag {
|
if *setshflag {
|
||||||
os.Setenv("SHELL", os.Args[0])
|
os.Setenv("SHELL", "hilbish")
|
||||||
|
|
||||||
|
path, err := exec.LookPath("hilbish")
|
||||||
|
if err == nil {
|
||||||
|
os.Setenv("SHELL", path)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lr = newLineReader("", false)
|
lr = newLineReader("", false)
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
local commander = require 'commander'
|
local commander = require 'commander'
|
||||||
|
|
||||||
commander.register('exec', function(args)
|
commander.register('exec', function(args)
|
||||||
|
if #args == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
hilbish.exec(args[1])
|
hilbish.exec(args[1])
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -1,3 +1,23 @@
|
||||||
|
local fs = require 'fs'
|
||||||
|
|
||||||
|
-- explanation: this specific function gives to us info about
|
||||||
|
-- the currently running source. this includes a path to the
|
||||||
|
-- source file (info.source)
|
||||||
|
-- we will use that to automatically load all commands by reading
|
||||||
|
-- all the files in this dir and just requiring it.
|
||||||
|
local info = debug.getinfo(1)
|
||||||
|
local commandDir = fs.dir(info.source)
|
||||||
|
if commandDir == '.' then return end
|
||||||
|
|
||||||
|
local commands = fs.readdir(commandDir)
|
||||||
|
for _, command in ipairs(commands) do
|
||||||
|
local name = command:gsub('%.lua', '') -- chop off extension
|
||||||
|
if name ~= 'init' then
|
||||||
|
-- skip this file (for obvious reasons)
|
||||||
|
require('nature.completions.' .. name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function hilbish.completion.handler(line, pos)
|
function hilbish.completion.handler(line, pos)
|
||||||
if type(line) ~= 'string' then error '#1 must be a string' end
|
if type(line) ~= 'string' then error '#1 must be a string' end
|
||||||
if type(pos) ~= 'number' then error '#2 must be a number' end
|
if type(pos) ~= 'number' then error '#2 must be a number' end
|
|
@ -0,0 +1,53 @@
|
||||||
|
local function curry(f)
|
||||||
|
return function (x) return function (y) return f(x,y) end end
|
||||||
|
end
|
||||||
|
|
||||||
|
local flags = {}
|
||||||
|
local function flag(f, description)
|
||||||
|
flags[f] = {description}
|
||||||
|
end
|
||||||
|
|
||||||
|
local addflag = curry(flag)
|
||||||
|
|
||||||
|
addflag '-A' 'Ask for password via askpass or $SUDO_ASKPASS'
|
||||||
|
addflag '-B' 'Ring the bell as part of the password prompt.'
|
||||||
|
|
||||||
|
hilbish.complete('command.sudo', function(query, ctx, fields)
|
||||||
|
table.remove(fields, 1)
|
||||||
|
local nonflags = table.filter(fields, function(v)
|
||||||
|
if v == '' then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return v:match '^%-' == nil
|
||||||
|
end)
|
||||||
|
|
||||||
|
if #fields == 1 or #nonflags == 0 then
|
||||||
|
-- complete commands or sudo flags
|
||||||
|
if query:match ('^%-') then
|
||||||
|
local compFlags = {}
|
||||||
|
for flg, flgstuff in pairs(flags) do
|
||||||
|
if flg:match('^' .. query) then
|
||||||
|
compFlags[flg] = flgstuff
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local compGroup = {
|
||||||
|
items = compFlags,
|
||||||
|
type = 'list'
|
||||||
|
}
|
||||||
|
|
||||||
|
return {compGroup}, query
|
||||||
|
end
|
||||||
|
|
||||||
|
local comps, pfx = hilbish.completion.bins(query, ctx, fields)
|
||||||
|
local compGroup = {
|
||||||
|
items = comps,
|
||||||
|
type = 'grid'
|
||||||
|
}
|
||||||
|
|
||||||
|
return {compGroup}, pfx
|
||||||
|
end
|
||||||
|
|
||||||
|
-- otherwise, get command flags
|
||||||
|
return hilbish.completion.call('command.' .. fields[2], query, ctx, fields)
|
||||||
|
end)
|
|
@ -1,4 +1,4 @@
|
||||||
// +build darwin linux
|
//go:build unix
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build windows
|
//go:build windows
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build darwin
|
//go:build darwin
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build linux
|
//go:build unix && !darwin
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build windows
|
//go:build windows
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue