mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "8b5dc6995017cd530cb64c0d80873c54a9ee5235" and "32b421d40294390d0b003ff70b14030ae6b2b449" have entirely different histories.
8b5dc69950
...
32b421d402
10
api.go
10
api.go
|
@ -48,15 +48,15 @@ func hilbishLoader(L *lua.LState) int {
|
||||||
host, _ := os.Hostname()
|
host, _ := os.Hostname()
|
||||||
username := curuser.Username
|
username := curuser.Username
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
greeting = `Welcome to {magenta}Hilbish{reset}, {cyan}` + curuser.Username + `{reset}.
|
||||||
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
|
||||||
}
|
|
||||||
|
|
||||||
greeting = `Welcome to {magenta}Hilbish{reset}, {cyan}` + username + `{reset}.
|
|
||||||
The nice lil shell for {blue}Lua{reset} fanatics!
|
The nice lil shell for {blue}Lua{reset} fanatics!
|
||||||
Check out the {blue}{bold}guide{reset} command to get started.
|
Check out the {blue}{bold}guide{reset} command to get started.
|
||||||
`
|
`
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
||||||
|
}
|
||||||
|
|
||||||
util.SetField(L, mod, "ver", lua.LString(version), "Hilbish version")
|
util.SetField(L, mod, "ver", lua.LString(version), "Hilbish version")
|
||||||
util.SetField(L, mod, "user", lua.LString(username), "Username of user")
|
util.SetField(L, mod, "user", lua.LString(username), "Username of user")
|
||||||
util.SetField(L, mod, "host", lua.LString(host), "Host name of the machine")
|
util.SetField(L, mod, "host", lua.LString(host), "Host name of the machine")
|
||||||
|
|
25
exec.go
25
exec.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -18,8 +17,6 @@ import (
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errNotExec = errors.New("not executable")
|
|
||||||
|
|
||||||
func runInput(input, origInput string) {
|
func runInput(input, origInput string) {
|
||||||
running = true
|
running = true
|
||||||
cmdString := aliases.Resolve(input)
|
cmdString := aliases.Resolve(input)
|
||||||
|
@ -140,9 +137,8 @@ func execCommand(cmd, old string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := lookpath(args[0])
|
err := lookpath(args[0])
|
||||||
if err == errNotExec {
|
if err == os.ErrPermission {
|
||||||
hooks.Em.Emit("command.no-perm", args[0])
|
hooks.Em.Emit("command.no-perm", args[0])
|
||||||
hooks.Em.Emit("command.not-executable", args[0])
|
|
||||||
return interp.NewExitStatus(126)
|
return interp.NewExitStatus(126)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
hooks.Em.Emit("command.not-found", args[0])
|
hooks.Em.Emit("command.not-found", args[0])
|
||||||
|
@ -160,17 +156,19 @@ func execCommand(cmd, old string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookpath(file string) error { // custom lookpath function so we know if a command is found *and* is executable
|
// custom lookpath function so we know if a command is found *and* has execute permission
|
||||||
|
func lookpath(file string) error {
|
||||||
skip := []string{"./", "/", "../", "~/"}
|
skip := []string{"./", "/", "../", "~/"}
|
||||||
for _, s := range skip {
|
for _, s := range skip {
|
||||||
if strings.HasPrefix(file, s) {
|
if strings.HasPrefix(file, s) {
|
||||||
return findExecutable(file)
|
err := findExecutable(file)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
|
||||||
path := filepath.Join(dir, file)
|
path := filepath.Join(dir, file)
|
||||||
err := findExecutable(path)
|
err := findExecutable(path)
|
||||||
if err == errNotExec {
|
if err == os.ErrPermission {
|
||||||
return err
|
return err
|
||||||
} else if err == nil {
|
} else if err == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -180,6 +178,17 @@ func lookpath(file string) error { // custom lookpath function so we know if a c
|
||||||
return os.ErrNotExist
|
return os.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findExecutable(name string) error {
|
||||||
|
f, err := os.Stat(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if m := f.Mode(); !m.IsDir() && m & 0111 != 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return os.ErrPermission
|
||||||
|
}
|
||||||
|
|
||||||
func splitInput(input string) ([]string, string) {
|
func splitInput(input string) ([]string, string) {
|
||||||
// end my suffering
|
// end my suffering
|
||||||
// TODO: refactor this garbage
|
// TODO: refactor this garbage
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
// +build linux darwin
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func findExecutable(path string) error {
|
|
||||||
f, err := os.Stat(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if m := f.Mode(); !m.IsDir() && m & 0111 != 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return errNotExec
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
// +build windows
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"path/filepath"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func findExecutable(path string) error {
|
|
||||||
nameExt := filepath.Ext(path)
|
|
||||||
if nameExt == "" {
|
|
||||||
for _, ext := range filepath.SplitList(os.Getenv("PATHEXT")) {
|
|
||||||
_, err := os.Stat(path + ext)
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := os.Stat(path)
|
|
||||||
if err == nil {
|
|
||||||
return errNotExec
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.ErrNotExist
|
|
||||||
}
|
|
Loading…
Reference in New Issue