mirror of https://github.com/Hilbis/Hilbish
Compare commits
6 Commits
4cc49d45c7
...
2a0cd1464a
Author | SHA1 | Date |
---|---|---|
TorchedSammy | 2a0cd1464a | |
TorchedSammy | f05ab921d7 | |
TorchedSammy | cb3d0a2e8e | |
TorchedSammy | 209abfac77 | |
TorchedSammy | 5e9ea9fead | |
TorchedSammy | 11f193b394 |
|
@ -1,9 +1,9 @@
|
||||||
-- Default Hilbish config
|
-- Default Hilbish config
|
||||||
lunacolors = require 'lunacolors'
|
local lunacolors = require 'lunacolors'
|
||||||
bait = require 'bait'
|
local bait = require 'bait'
|
||||||
|
|
||||||
function doPrompt(fail)
|
function doPrompt(fail)
|
||||||
prompt(lunacolors.format(
|
hilbish.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,7 +7,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -63,17 +62,8 @@ 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(userConfigDir), "User's config directory")
|
util.SetField(L, hshuser, "config", lua.LString(confDir), "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,6 +27,7 @@ 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
|
||||||
|
@ -37,31 +38,30 @@ var (
|
||||||
func main() {
|
func main() {
|
||||||
curuser, _ = user.Current()
|
curuser, _ = user.Current()
|
||||||
homedir := curuser.HomeDir
|
homedir := curuser.HomeDir
|
||||||
confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config")
|
confDir, _ = os.UserConfigDir()
|
||||||
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 == "" {
|
||||||
// we'll add *our* default if its empty (wont be if its changed comptime)
|
defaultHistPath = filepath.Join(userDataDir, "hilbish", ".hilbish-history")
|
||||||
if _, err := os.Stat(filepath.Join(confDir, "hilbish")); os.IsNotExist(err) {
|
|
||||||
defaultHistPath = filepath.Join(homedir, "/.hilbish-history")
|
|
||||||
} else {
|
} else {
|
||||||
defaultHistPath = filepath.Join(confDir, "hilbish", ".hilbish-history")
|
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".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,34 +113,29 @@ 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) {
|
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath {
|
||||||
// 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)
|
||||||
input, err := os.ReadFile(".hilbishrc.lua")
|
_, 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
|
||||||
input, err = os.ReadFile(sampleConfPath)
|
_, 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create it using either default config we found
|
runConfig(confpath)
|
||||||
err = os.WriteFile(defaultConfPath, input, 0644)
|
} else {
|
||||||
if err != nil {
|
|
||||||
// If that fails, bail
|
|
||||||
fmt.Println("Error creating config file")
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
go handleSignals()
|
|
||||||
luaInit()
|
|
||||||
runLogin()
|
|
||||||
runConfig(*configflag)
|
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,8 +30,10 @@ 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
|
||||||
table.insert(recentDirs, 1, path)
|
|
||||||
recentDirs[11] = nil
|
recentDirs[11] = nil
|
||||||
|
if recentDirs[#recentDirs - 1] ~= path then
|
||||||
|
table.insert(recentDirs, 1, path)
|
||||||
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue