diff --git a/README.md b/README.md index b4c6a50..479bee0 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Croissant looks at the first word of your entry and runs any command it matches. ## Caveats -- Pretty printing values can be expensive in CPU and memory: avoid dumping either large of deeply nested tables. You can play with the `dump.depthLimit` and `dump.itemsLimit` value in your `~/.croissantrc` or the `depth` command to avoid exploring to far down in complex tables. +- Pretty printing values can be expensive in CPU and memory: avoid dumping either large of deeply nested tables. You can play with the `dump.depthLimit` and `dump.itemsLimit` value in your `$XDG_CONFIG_HOME/croissantrc` or `~/.croissantrc`, or the `depth` command to avoid exploring to far down in complex tables. - The debugger will slow your program down. Croissant will try and clear hooks whenever possible but if you know you won't hit anymore breakpoints, do a `clear` before doing `continue`. - A breakpoint on a function name will not work if the function is not called by its name in your code. Example: @@ -133,7 +133,7 @@ call(stopMe) ## Configuration -You can customize some aspect of croissant by writing a `~/.croissantrc` lua file. Here are the default values than you can overwrite: +You can customize some aspect of croissant by writing a `$XDG_CONFIG_HOME/croissantrc` or `~/.croissantrc` lua file. Here are the default values than you can overwrite: ```lua return { @@ -143,8 +143,8 @@ return { continuationPrompt = ".... ", -- Maximum amount of remembered lines - -- Croissant manages two history file: one for the repl (~/.croissant_history), - -- one for the debugger (~/.croissant_debugger_history) + -- Croissant manages two history file: one for the repl ($XDG_STATE_HOME/croissant_history), + -- one for the debugger ($XDG_STATE_HOME/croissant_debugger_history) historyLimit = 1000, -- How many rows `where` should print around the current line diff --git a/croissant/conf.lua b/croissant/conf.lua index bda04e2..2375aec 100644 --- a/croissant/conf.lua +++ b/croissant/conf.lua @@ -83,9 +83,10 @@ local default = { } } --- Read from ~/.croissantrc +-- Read from $XDG_CONFIG_HOME/croissantrc or ~/.croissantrc local user = {} -local file, _ = io.open(os.getenv "HOME" .. "/.croissantrc", "r") +local xdg_config_home = os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME") .. "/.config" +local file = io.open(xdg_config_home .. "/croissantrc", "r") or io.open(os.getenv "HOME" .. "/.croissantrc", "r") if file then local rc = file:read("*all") diff --git a/croissant/do.lua b/croissant/do.lua index 2fb9192..ed1581e 100644 --- a/croissant/do.lua +++ b/croissant/do.lua @@ -263,10 +263,25 @@ local function runFile(script, arguments) end end +local function getHistoryFile(debugger, mode) + local xdg_state_home = os.getenv("XDG_STATE_HOME") or os.getenv("HOME") .. "/.local/state" + + local filename + if debugger == true then + filename = "croissant_debugger_history" + else + filename = "croissant_history" + end + + local file = io.open(xdg_state_home .. "/" .. filename, mode) + + return file +end + local function loadHistory() local history = {} - local historyFile = io.open(os.getenv "HOME" .. "/.croissant_history", "r") + local historyFile = getHistoryFile(false, "r") if historyFile then for line in historyFile:lines() do @@ -284,7 +299,7 @@ end local function loadDebugHistory() local history = {} - local historyFile = io.open(os.getenv "HOME" .. "/.croissant_debugger_history", "r") + local historyFile = getHistoryFile(true, "r") if historyFile then for line in historyFile:lines() do @@ -300,7 +315,7 @@ local function loadDebugHistory() end local function appendToHistory(code) - local historyFile = io.open(os.getenv "HOME" .. "/.croissant_history", "a+") + local historyFile = getHistoryFile(false, "a+") if historyFile then historyFile:write(code:gsub("\n", "\\n") .. "\n") @@ -310,7 +325,7 @@ local function appendToHistory(code) end local function appendToDebugHistory(code) - local historyFile = io.open(os.getenv "HOME" .. "/.croissant_debugger_history", "a+") + local historyFile = getHistoryFile(true, "a+") if historyFile then historyFile:write(code:gsub("\n", "\\n") .. "\n")