Compare commits

..

No commits in common. "8f94990fc3ebb1d5fe91978a1f40b7cfb94c0c18" and "6bb2a2f8c80391b5cdf2fe7bc2f662b399b7842b" have entirely different histories.

4 changed files with 14 additions and 48 deletions

View File

@ -60,11 +60,11 @@ sudo make install
sudo make all
```
Alternatively, if you use Arch Linux, you can compile Hilbish with an **(unofficial)** AUR package:
Alternativly, 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:
If you want the latest and greatest, you can install and compile from latest git commit
```sh
yay -S hilbish-git
```

19
lua.go
View File

@ -3,9 +3,7 @@ package main
import (
"fmt"
"os"
"os/exec"
"strings"
"syscall"
"hilbish/golibs/bait"
"hilbish/golibs/commander"
@ -33,7 +31,6 @@ func LuaInit() {
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
l.SetGlobal("alias", l.NewFunction(hshalias))
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
l.SetGlobal("exec", l.NewFunction(hshexec))
// Add fs module to Lua
l.PreloadModule("fs", fs.Loader)
@ -130,19 +127,3 @@ func hshappendPath(L *lua.LState) int {
return 0
}
func hshexec(L *lua.LState) int {
cmd := L.CheckString(1)
cmdArgs, _ := splitInput(cmd)
cmdPath, err := exec.LookPath(cmdArgs[0])
if err != nil {
fmt.Println(err)
// if we get here, cmdPath will be nothing
// therefore nothing will run
}
// syscall.Exec requires an absolute path to a binary
// path, args, string slice of environments
syscall.Exec(cmdPath, cmdArgs, os.Environ())
return 0
}

25
main.go
View File

@ -35,7 +35,6 @@ var (
hooks bait.Bait
interactive bool
login bool // Are we the login shell?
noexecute bool // Should we run Lua or only report syntax errors
)
func main() {
@ -48,14 +47,14 @@ func main() {
setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path")
cmdflag := getopt.StringLong("command", 'c', "", /*TODO: Help description*/ "")
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("interactive", 'i', "Force Hilbish to be an interactive shell")
getopt.BoolLong("noexec", 'n', "Don't execute and only report Lua syntax errors")
// loginshflag
// TODO: issue #37
_ = getopt.BoolLong("login", 'l', "Makes Hilbish act like a login shell")
_ = getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
getopt.Parse()
loginshflag := getopt.Lookup('l').Seen()
interactiveflag := getopt.Lookup('i').Seen()
noexecflag := getopt.Lookup('n').Seen()
if *cmdflag == "" || interactiveflag {
interactive = true
@ -65,10 +64,6 @@ func main() {
interactive = false
}
if noexecflag {
noexecute = true
}
// first arg, first character
if loginshflag || os.Args[0][0] == '-' {
login = true
@ -108,12 +103,15 @@ func main() {
}
}
go HandleSignals()
LuaInit()
RunLogin()
RunInput(*cmdflag)
RunConfig(*configflag)
readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history")
RunInput(*cmdflag)
if getopt.NArgs() > 0 {
err := l.DoFile(getopt.Arg(0))
if err != nil {
@ -123,11 +121,6 @@ func main() {
os.Exit(0)
}
readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history")
go HandleSignals()
for interactive {
running = false

View File

@ -16,17 +16,9 @@ import (
)
func RunInput(input string) {
// First try to load input, essentially compiling to bytecode
fn, err := l.LoadString(input)
if err != nil && noexecute {
fmt.Println(err)
return
}
// And if there's no syntax errors and -n isnt provided, run
if !noexecute {
l.Push(fn)
err = l.PCall(0, lua.MultRet, nil)
}
// First try to run user input in Lua
err := l.DoString(input)
if err == nil {
// If it succeeds, add to history and prompt again
HandleHistory(input)