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
|
||||
local lunacolors = require 'lunacolors'
|
||||
local bait = require 'bait'
|
||||
lunacolors = require 'lunacolors'
|
||||
bait = require 'bait'
|
||||
|
||||
function doPrompt(fail)
|
||||
hilbish.prompt(lunacolors.format(
|
||||
prompt(lunacolors.format(
|
||||
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆ '
|
||||
))
|
||||
end
|
||||
|
|
12
api.go
12
api.go
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
@ -62,8 +63,17 @@ The nice lil shell for {blue}Lua{reset} fanatics!
|
|||
|
||||
// hilbish.userDir table
|
||||
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.Document(L, hshuser, "User directories to store configs and/or modules.")
|
||||
L.SetField(mod, "userDir", hshuser)
|
||||
|
|
55
main.go
55
main.go
|
@ -27,7 +27,6 @@ var (
|
|||
luaCompletions = map[string]*lua.LFunction{}
|
||||
|
||||
confDir string
|
||||
userDataDir string
|
||||
curuser *user.User
|
||||
|
||||
hooks bait.Bait
|
||||
|
@ -38,30 +37,31 @@ var (
|
|||
func main() {
|
||||
curuser, _ = user.Current()
|
||||
homedir := curuser.HomeDir
|
||||
confDir, _ = os.UserConfigDir()
|
||||
confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config")
|
||||
preloadPath = strings.Replace(preloadPath, "~", 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 == "" {
|
||||
// we'll add *our* default if its empty (wont be if its changed comptime)
|
||||
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua")
|
||||
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")
|
||||
}
|
||||
} else {
|
||||
// else do ~ substitution
|
||||
defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua")
|
||||
}
|
||||
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 {
|
||||
defaultHistPath = filepath.Join(confDir, "hilbish", ".hilbish-history")
|
||||
}
|
||||
} else {
|
||||
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history")
|
||||
// else do ~ substitution
|
||||
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbishrc.lua")
|
||||
}
|
||||
helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags")
|
||||
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
|
||||
|
@ -113,30 +113,35 @@ func main() {
|
|||
os.Setenv("SHELL", os.Args[0])
|
||||
}
|
||||
|
||||
go handleSignals()
|
||||
luaInit()
|
||||
runLogin()
|
||||
// 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
|
||||
// (this is assuming the current dir is Hilbish's git)
|
||||
_, err := os.ReadFile(".hilbishrc.lua")
|
||||
confpath := ".hilbishrc.lua"
|
||||
input, err := os.ReadFile(".hilbishrc.lua")
|
||||
if err != nil {
|
||||
// If it wasnt found, go to the real sample conf
|
||||
_, err = os.ReadFile(sampleConfPath)
|
||||
confpath = sampleConfPath
|
||||
input, err = os.ReadFile(sampleConfPath)
|
||||
if err != nil {
|
||||
fmt.Println("could not find .hilbishrc.lua or", sampleConfPath)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
runConfig(confpath)
|
||||
} else {
|
||||
runConfig(*configflag)
|
||||
// Create it using either default config we found
|
||||
err = os.WriteFile(defaultConfPath, input, 0644)
|
||||
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 {
|
||||
scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
|
||||
for scanner.Scan() {
|
||||
|
|
|
@ -30,10 +30,8 @@ commander.register('cd', function (args)
|
|||
bait.throw('cd', path)
|
||||
|
||||
-- add to table of recent dirs
|
||||
table.insert(recentDirs, 1, path)
|
||||
recentDirs[11] = nil
|
||||
if recentDirs[#recentDirs - 1] ~= path then
|
||||
table.insert(recentDirs, 1, path)
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue