mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "2a0cd1464a81574f871b117f93d0982334e36e86" and "4cc49d45c7d2a923110b062ce159e889d6435e98" have entirely different histories.
2a0cd1464a
...
4cc49d45c7
|
@ -1,9 +1,9 @@
|
||||||
-- Default Hilbish config
|
-- Default Hilbish config
|
||||||
local lunacolors = require 'lunacolors'
|
lunacolors = require 'lunacolors'
|
||||||
local bait = require 'bait'
|
bait = require 'bait'
|
||||||
|
|
||||||
function doPrompt(fail)
|
function doPrompt(fail)
|
||||||
hilbish.prompt(lunacolors.format(
|
prompt(lunacolors.format(
|
||||||
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆ '
|
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆ '
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
12
api.go
12
api.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -62,8 +63,17 @@ The nice lil shell for {blue}Lua{reset} fanatics!
|
||||||
|
|
||||||
// hilbish.userDir table
|
// hilbish.userDir table
|
||||||
hshuser := L.NewTable()
|
hshuser := L.NewTable()
|
||||||
|
userConfigDir, _ := os.UserConfigDir()
|
||||||
|
userDataDir := ""
|
||||||
|
// i honestly dont know what directories to use for this
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
userDataDir = getenv("XDG_DATA_HOME", curuser.HomeDir + "/.local/share")
|
||||||
|
default:
|
||||||
|
userDataDir = filepath.Join(userConfigDir)
|
||||||
|
}
|
||||||
|
|
||||||
util.SetField(L, hshuser, "config", lua.LString(confDir), "User's config directory")
|
util.SetField(L, hshuser, "config", lua.LString(userConfigDir), "User's config directory")
|
||||||
util.SetField(L, hshuser, "data", lua.LString(userDataDir), "XDG data directory")
|
util.SetField(L, hshuser, "data", lua.LString(userDataDir), "XDG data directory")
|
||||||
util.Document(L, hshuser, "User directories to store configs and/or modules.")
|
util.Document(L, hshuser, "User directories to store configs and/or modules.")
|
||||||
L.SetField(mod, "userDir", hshuser)
|
L.SetField(mod, "userDir", hshuser)
|
||||||
|
|
53
main.go
53
main.go
|
@ -27,7 +27,6 @@ var (
|
||||||
luaCompletions = map[string]*lua.LFunction{}
|
luaCompletions = map[string]*lua.LFunction{}
|
||||||
|
|
||||||
confDir string
|
confDir string
|
||||||
userDataDir string
|
|
||||||
curuser *user.User
|
curuser *user.User
|
||||||
|
|
||||||
hooks bait.Bait
|
hooks bait.Bait
|
||||||
|
@ -38,30 +37,31 @@ var (
|
||||||
func main() {
|
func main() {
|
||||||
curuser, _ = user.Current()
|
curuser, _ = user.Current()
|
||||||
homedir := curuser.HomeDir
|
homedir := curuser.HomeDir
|
||||||
confDir, _ = os.UserConfigDir()
|
confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config")
|
||||||
preloadPath = strings.Replace(preloadPath, "~", homedir, 1)
|
preloadPath = strings.Replace(preloadPath, "~", homedir, 1)
|
||||||
sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1)
|
sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1)
|
||||||
|
|
||||||
// i honestly dont know what directories to use for this
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "linux":
|
|
||||||
userDataDir = getenv("XDG_DATA_HOME", curuser.HomeDir + "/.local/share")
|
|
||||||
default:
|
|
||||||
// this is fine on windows, dont know about others
|
|
||||||
userDataDir = confDir
|
|
||||||
}
|
|
||||||
|
|
||||||
if defaultConfDir == "" {
|
if defaultConfDir == "" {
|
||||||
// we'll add *our* default if its empty (wont be if its changed comptime)
|
// we'll add *our* default if its empty (wont be if its changed comptime)
|
||||||
|
if _, err := os.Stat(filepath.Join(confDir, "hilbish")); os.IsNotExist(err) {
|
||||||
|
defaultConfPath = filepath.Join(homedir, "/.hilbishrc.lua")
|
||||||
|
} else {
|
||||||
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua")
|
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// else do ~ substitution
|
// else do ~ substitution
|
||||||
defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua")
|
defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua")
|
||||||
}
|
}
|
||||||
if defaultHistDir == "" {
|
if defaultHistDir == "" {
|
||||||
defaultHistPath = filepath.Join(userDataDir, "hilbish", ".hilbish-history")
|
// we'll add *our* default if its empty (wont be if its changed comptime)
|
||||||
|
if _, err := os.Stat(filepath.Join(confDir, "hilbish")); os.IsNotExist(err) {
|
||||||
|
defaultHistPath = filepath.Join(homedir, "/.hilbish-history")
|
||||||
} else {
|
} else {
|
||||||
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history")
|
defaultHistPath = filepath.Join(confDir, "hilbish", ".hilbish-history")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// else do ~ substitution
|
||||||
|
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbishrc.lua")
|
||||||
}
|
}
|
||||||
helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags")
|
helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags")
|
||||||
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
|
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
|
||||||
|
@ -113,29 +113,34 @@ func main() {
|
||||||
os.Setenv("SHELL", os.Args[0])
|
os.Setenv("SHELL", os.Args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
go handleSignals()
|
|
||||||
luaInit()
|
|
||||||
runLogin()
|
|
||||||
// If user's config doesn't exixt,
|
// If user's config doesn't exixt,
|
||||||
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath {
|
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) {
|
||||||
// Read default from current directory
|
// Read default from current directory
|
||||||
// (this is assuming the current dir is Hilbish's git)
|
// (this is assuming the current dir is Hilbish's git)
|
||||||
_, err := os.ReadFile(".hilbishrc.lua")
|
input, err := os.ReadFile(".hilbishrc.lua")
|
||||||
confpath := ".hilbishrc.lua"
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If it wasnt found, go to the real sample conf
|
// If it wasnt found, go to the real sample conf
|
||||||
_, err = os.ReadFile(sampleConfPath)
|
input, err = os.ReadFile(sampleConfPath)
|
||||||
confpath = sampleConfPath
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("could not find .hilbishrc.lua or", sampleConfPath)
|
fmt.Println("could not find .hilbishrc.lua or", sampleConfPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runConfig(confpath)
|
// Create it using either default config we found
|
||||||
} else {
|
err = os.WriteFile(defaultConfPath, input, 0644)
|
||||||
runConfig(*configflag)
|
if err != nil {
|
||||||
|
// If that fails, bail
|
||||||
|
fmt.Println("Error creating config file")
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
go handleSignals()
|
||||||
|
luaInit()
|
||||||
|
runLogin()
|
||||||
|
runConfig(*configflag)
|
||||||
|
|
||||||
if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
|
if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
|
||||||
scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
|
scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
|
||||||
|
|
|
@ -30,10 +30,8 @@ commander.register('cd', function (args)
|
||||||
bait.throw('cd', path)
|
bait.throw('cd', path)
|
||||||
|
|
||||||
-- add to table of recent dirs
|
-- add to table of recent dirs
|
||||||
recentDirs[11] = nil
|
|
||||||
if recentDirs[#recentDirs - 1] ~= path then
|
|
||||||
table.insert(recentDirs, 1, path)
|
table.insert(recentDirs, 1, path)
|
||||||
end
|
recentDirs[11] = nil
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue