Compare commits

...

5 Commits

Author SHA1 Message Date
TorchedSammy bbfe28dbae chore: fix formatting and add comma 2021-04-07 09:18:06 -04:00
devins2518 140bdeebd7
chore: fix default luarc grammar (#24) 2021-04-07 09:10:11 -04:00
TorchedSammy 0fa3d50db7 feat: add -C flag (closes #20) 2021-04-07 08:40:40 -04:00
TorchedSammy 2b01d5edb2 feat: always print prompt on newline; complete missing linefeed - "\r" 2021-04-06 21:12:29 -04:00
TorchedSammy c0f34fd784 fix: return ansikit in setTitle function 2021-04-06 12:55:02 -04:00
4 changed files with 21 additions and 11 deletions

View File

@ -8,9 +8,9 @@ function doPrompt(fail)
))
end
print(ansikit.format('Welcome {cyan}'.. os.getenv 'USER' ..
'{reset} to {magenta}Hilbish{reset},\n' ..
'the nice lil shell for {blue}Lua{reset} fanatics!\n'))
print(ansikit.format('Welcome to {magenta}Hilbish{reset}, {cyan}' ..
os.getenv 'USER' .. '{reset}.\n' ..
'The nice lil shell for {blue}Lua{reset} fanatics!\n'))
doPrompt()

View File

@ -169,7 +169,7 @@ ansikit.saveState = function()
end
ansikit.setTitle = function(text)
ansikit.printCode (']2;' .. text, true)
return ansikit.printCode(']2;' .. text, true)
end
ansikit.showCursor = function()

5
lua.go
View File

@ -17,7 +17,7 @@ prompt(ansikit.format(
))
`
func LuaInit() {
func LuaInit(confpath string) {
l = lua.NewState()
l.OpenLibs()
@ -60,9 +60,8 @@ func LuaInit() {
}
}
homedir, _ := os.UserHomeDir()
// Run config
err = l.DoFile(homedir + "/.hilbishrc.lua")
err = l.DoFile(confpath)
if err != nil {
fmt.Fprintln(os.Stderr, err,
"\nAn error has occured while loading your config! Falling back to minimal default config.\n")

19
main.go
View File

@ -14,7 +14,7 @@ import (
"github.com/akamensky/argparse"
"github.com/bobappleyard/readline"
"github.com/yuin/gopher-lua"
"golang.org/x/term"
)
const version = "0.3.1"
@ -31,6 +31,9 @@ var bait hooks.Bait
var homedir string
func main() {
homedir, _ = os.UserHomeDir()
defaultconfpath := homedir + "/.hilbishrc.lua"
parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers")
verflag := parser.Flag("v", "version", &argparse.Options{
Required: false,
@ -40,6 +43,11 @@ func main() {
Required: false,
Help: "Sets $SHELL to Hilbish's executed path",
})
configflag := parser.String("C", "config", &argparse.Options{
Required: false,
Help: "Sets the path to Hilbish's config",
Default: defaultconfpath,
})
err := parser.Parse(os.Args)
// If invalid flags or --help/-h,
@ -57,9 +65,8 @@ func main() {
// Set $SHELL if the user wants to
if *setshflag { os.Setenv("SHELL", os.Args[0]) }
homedir, _ = os.UserHomeDir()
// If user's config doesn't exixt,
if _, err := os.Stat(homedir + "/.hilbishrc.lua"); os.IsNotExist(err) {
if _, err := os.Stat(defaultconfpath); os.IsNotExist(err) {
// Read default from current directory
// (this is assuming the current dir is Hilbish's git)
input, err := os.ReadFile(".hilbishrc.lua")
@ -83,7 +90,7 @@ func main() {
}
HandleSignals()
LuaInit()
LuaInit(*configflag)
readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history")
@ -111,6 +118,10 @@ func main() {
}
}
RunInput(input)
termwidth, _, err := term.GetSize(0)
if err != nil { continue }
fmt.Printf("\u001b[7m∆\u001b[0m" + strings.Repeat(" ", termwidth - 1) + "\r")
}
}