mirror of https://github.com/Hilbis/Hilbish
fix: runtime errors on linux
this fixes out of bounds error since we tried to split the username for '\' which is only valid on windows, so i added it for windows onlypull/69/head
parent
7c815022a9
commit
c95b0b55be
|
@ -5,6 +5,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pborman/getopt"
|
"github.com/pborman/getopt"
|
||||||
|
@ -22,7 +23,11 @@ func HilbishLoader(L *lua.LState) int {
|
||||||
mod := L.SetFuncs(L.NewTable(), exports)
|
mod := L.SetFuncs(L.NewTable(), exports)
|
||||||
|
|
||||||
host, _ := os.Hostname()
|
host, _ := os.Hostname()
|
||||||
username := strings.Split(curuser.Username, "\\")[1] // for some reason Username includes the hostname on windows
|
username := curuser.Username
|
||||||
|
// this will be baked into binary since GOOS is a constant
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
||||||
|
}
|
||||||
|
|
||||||
L.SetField(mod, "ver", lua.LString(version))
|
L.SetField(mod, "ver", lua.LString(version))
|
||||||
L.SetField(mod, "user", lua.LString(username))
|
L.SetField(mod, "user", lua.LString(username))
|
||||||
|
|
7
main.go
7
main.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
@ -265,7 +266,11 @@ func fmtPrompt() string {
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
cwd = strings.Replace(cwd, curuser.HomeDir, "~", 1)
|
cwd = strings.Replace(cwd, curuser.HomeDir, "~", 1)
|
||||||
username := strings.Split(curuser.Username, "\\")[1] // for some reason Username includes the hostname on windows
|
username := curuser.Username
|
||||||
|
// this will be baked into binary since GOOS is a constant
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
||||||
|
}
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"d", cwd,
|
"d", cwd,
|
||||||
|
|
Loading…
Reference in New Issue