Compare commits

..

13 Commits

Author SHA1 Message Date
sammyette edcc1b39f0
docs: add todo to lua.go 2021-06-09 20:43:01 -04:00
sammyette 646cb93dec
feat: support comptime sample conf declaration 2021-06-09 20:33:30 -04:00
sammyette 13dc0cd857
feat: support comptime config dir declaration 2021-06-09 20:30:53 -04:00
sammyette 792ce996d3
fix: return 0 exit code when cd with noarg instead of throwing hook explicitly 2021-06-09 20:30:12 -04:00
sammyette 95dee1f4dd
fix: check aliases before going to sh interp 2021-06-09 19:16:08 -04:00
sammyette 14064eceda
chore: cleanup and remove extra spaces 2021-06-09 18:41:37 -04:00
sammyette ce5ac86a4c
docs: make build for stable release more clear 2021-06-09 18:19:52 -04:00
sammyette fa1cdbefa2
docs: move aur install step up 2021-06-09 18:18:23 -04:00
sammyette a9b39834b3
docs: make build steps clearer 2021-06-09 18:16:04 -04:00
sammyette 6cbebcbae9
docs: fix arch install step for readline 2021-06-09 18:13:43 -04:00
sammyette 42c22aac96
docs: add newline between readline dep and fedora install step 2021-06-09 18:12:45 -04:00
sammyette 084f049ba5
style: add spaces between multiply op 2021-06-09 18:10:34 -04:00
Daniel de Sá ea67ae228c
docs: add readline install for arch (#60) 2021-06-09 14:38:04 -04:00
6 changed files with 63 additions and 32 deletions

View File

@ -41,11 +41,21 @@ 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
@ -61,6 +71,11 @@ 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
@ -74,23 +89,16 @@ 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

1
lua.go
View File

@ -42,6 +42,7 @@ 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

22
main.go
View File

@ -29,17 +29,25 @@ var (
curuser *user.User curuser *user.User
hooks bait.Bait hooks bait.Bait
defaultConfPath string
) )
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")
@ -81,21 +89,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 "real default" // If it wasnt found, go to the real sample conf
input, err = os.ReadFile("/usr/share/hilbish/.hilbishrc.lua") input, err = os.ReadFile(sampleConfPath)
if err != nil { if err != nil {
fmt.Println("could not find .hilbishrc.lua or /usr/share/hilbish/.hilbishrc.lua") fmt.Println("could not find .hilbishrc.lua or", sampleConfPath)
return return
} }
} }
// Create it using either default config we found // Create it using either default config we found
err = os.WriteFile(homedir + "/.hilbishrc.lua", input, 0644) err = os.WriteFile(defaultConfPath, 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")

View File

@ -35,7 +35,8 @@ 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()
@ -46,7 +47,7 @@ do
local virt_G = { } local virt_G = { }
setmetatable(_G, { setmetatable(_G, {
__index = function (self, key) __index = function (_, 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
@ -56,7 +57,7 @@ do
return virt_G[key] return virt_G[key]
end, end,
__newindex = function (self, key, value) __newindex = function (_, 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

View File

@ -18,6 +18,17 @@ 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 {
@ -149,7 +160,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),

View File

@ -10,6 +10,8 @@ var (
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua;' .. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?/?.lua;'
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua'` .. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua'`
preloadPath = "/usr/share/hilbish/preload.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 prompt string // Prompt will always get changed anyway
multilinePrompt = "> " multilinePrompt = "> "