fix: errors and make login rc run before config

pull/46/head
sammy 2021-05-01 14:17:14 -04:00
parent 38f1d62598
commit 7f8d8db53e
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
2 changed files with 11 additions and 7 deletions

13
lua.go
View File

@ -17,7 +17,7 @@ prompt(ansikit.format(
)) ))
` `
func LuaInit(confpath string) { func LuaInit() {
l = lua.NewState() l = lua.NewState()
l.OpenLibs() l.OpenLibs()
@ -66,12 +66,12 @@ func LuaInit(confpath string) {
"Missing preload file, builtins may be missing.") "Missing preload file, builtins may be missing.")
} }
} }
}
// Run config func RunConfig(confpath string) {
if !interactive { if !interactive {
return return
} }
err = l.DoFile(confpath) err := l.DoFile(confpath)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err, fmt.Fprintln(os.Stderr, err,
"\nAn error has occured while loading your config! Falling back to minimal default config.\n") "\nAn error has occured while loading your config! Falling back to minimal default config.\n")
@ -84,7 +84,10 @@ func RunLogin() {
if _, err := os.Stat(homedir + "/.hprofile.lua"); os.IsNotExist(err) { if _, err := os.Stat(homedir + "/.hprofile.lua"); os.IsNotExist(err) {
return return
} }
err = l.DoFile(homedir + "/.hprofile.lua") if !login {
return
}
err := l.DoFile(homedir + "/.hprofile.lua")
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err, fmt.Fprintln(os.Stderr, err,
"\nAn error has occured while loading your login config!n") "\nAn error has occured while loading your login config!n")

View File

@ -61,7 +61,7 @@ func main() {
} }
// first arg, first character // first arg, first character
if loginshflag || os.Args[0][0] == "-" { if loginshflag || os.Args[0][0] == '-' {
login = true login = true
} }
@ -100,8 +100,9 @@ func main() {
} }
go HandleSignals() go HandleSignals()
LuaInit(*configflag) LuaInit()
RunLogin() RunLogin()
RunConfig(*configflag)
readline.Completer = readline.FilenameCompleter readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history") readline.LoadHistory(homedir + "/.hilbish-history")