feat: make hilbish act like a login shell

when a user logs in with hilbish as the user shell,
or -l/--login is passed
resolves #37
pull/46/head
sammy 2021-05-01 14:08:42 -04:00
parent e580112e1b
commit 38f1d62598
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
2 changed files with 21 additions and 3 deletions

11
lua.go
View File

@ -80,6 +80,17 @@ func LuaInit(confpath string) {
}
}
func RunLogin() {
if _, err := os.Stat(homedir + "/.hprofile.lua"); os.IsNotExist(err) {
return
}
err = l.DoFile(homedir + "/.hprofile.lua")
if err != nil {
fmt.Fprintln(os.Stderr, err,
"\nAn error has occured while loading your login config!n")
}
}
func hshprompt(L *lua.LState) int {
prompt = L.CheckString(1)

13
main.go
View File

@ -21,8 +21,7 @@ const version = "0.4.0-dev.7"
var (
l *lua.LState
// User's prompt, this will get set when lua side is initialized
prompt string
prompt string // User's prompt, this will get set when lua side is initialized
multilinePrompt = "> "
commands = map[string]bool{}
@ -30,8 +29,9 @@ var (
hooks bait.Bait
homedir string
running bool
running bool // Is a command currently running
interactive bool
login bool // Are we the login shell?
)
func main() {
@ -49,6 +49,7 @@ func main() {
_ = getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
getopt.Parse()
loginshflag := getopt.Lookup('l').Seen()
interactiveflag := getopt.Lookup('i').Seen()
if *cmdflag == "" || interactiveflag {
@ -59,6 +60,11 @@ func main() {
interactive = false
}
// first arg, first character
if loginshflag || os.Args[0][0] == "-" {
login = true
}
if *verflag {
fmt.Printf("Hilbish v%s\n", version)
os.Exit(0)
@ -95,6 +101,7 @@ func main() {
go HandleSignals()
LuaInit(*configflag)
RunLogin()
readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history")