mirror of https://github.com/Hilbis/Hilbish
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 #37pull/46/head
parent
e580112e1b
commit
38f1d62598
11
lua.go
11
lua.go
|
@ -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 {
|
func hshprompt(L *lua.LState) int {
|
||||||
prompt = L.CheckString(1)
|
prompt = L.CheckString(1)
|
||||||
|
|
||||||
|
|
13
main.go
13
main.go
|
@ -21,8 +21,7 @@ const version = "0.4.0-dev.7"
|
||||||
var (
|
var (
|
||||||
l *lua.LState
|
l *lua.LState
|
||||||
|
|
||||||
// User's prompt, this will get set when lua side is initialized
|
prompt string // User's prompt, this will get set when lua side is initialized
|
||||||
prompt string
|
|
||||||
multilinePrompt = "> "
|
multilinePrompt = "> "
|
||||||
|
|
||||||
commands = map[string]bool{}
|
commands = map[string]bool{}
|
||||||
|
@ -30,8 +29,9 @@ var (
|
||||||
|
|
||||||
hooks bait.Bait
|
hooks bait.Bait
|
||||||
homedir string
|
homedir string
|
||||||
running bool
|
running bool // Is a command currently running
|
||||||
interactive bool
|
interactive bool
|
||||||
|
login bool // Are we the login shell?
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -49,6 +49,7 @@ func main() {
|
||||||
_ = getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
|
_ = getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
|
||||||
|
|
||||||
getopt.Parse()
|
getopt.Parse()
|
||||||
|
loginshflag := getopt.Lookup('l').Seen()
|
||||||
interactiveflag := getopt.Lookup('i').Seen()
|
interactiveflag := getopt.Lookup('i').Seen()
|
||||||
|
|
||||||
if *cmdflag == "" || interactiveflag {
|
if *cmdflag == "" || interactiveflag {
|
||||||
|
@ -59,6 +60,11 @@ func main() {
|
||||||
interactive = false
|
interactive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// first arg, first character
|
||||||
|
if loginshflag || os.Args[0][0] == "-" {
|
||||||
|
login = true
|
||||||
|
}
|
||||||
|
|
||||||
if *verflag {
|
if *verflag {
|
||||||
fmt.Printf("Hilbish v%s\n", version)
|
fmt.Printf("Hilbish v%s\n", version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -95,6 +101,7 @@ func main() {
|
||||||
|
|
||||||
go HandleSignals()
|
go HandleSignals()
|
||||||
LuaInit(*configflag)
|
LuaInit(*configflag)
|
||||||
|
RunLogin()
|
||||||
|
|
||||||
readline.Completer = readline.FilenameCompleter
|
readline.Completer = readline.FilenameCompleter
|
||||||
readline.LoadHistory(homedir + "/.hilbish-history")
|
readline.LoadHistory(homedir + "/.hilbish-history")
|
||||||
|
|
Loading…
Reference in New Issue