dune
dune copied to clipboard
Config file
What a config file could contain:
- Color theme
- Keyboard shortcuts
- Paths to dune preludes
The config file should be read from ~/.config/dune/
or XDG_CONFIG_DIR
or whatever the platform default is. This can be done with the dirs-next
crate.
This would be a really nice enhancement. We could do something like a CONFIG
static variable using lazy static:
struct Config {
red: Color,
blue: Color,
// ...
prelude_path: PathBuf,
}
lazy_static! {
static ref CONFIG: Config = Config::read();
}
fn main() {
parse(read(&CONFIG.prelude_path));
}
Normally, I would want to keep something like this encapsulated within the Dune interpreter itself, but that's impossible to do if we don't know the custom prelude path.
I'd like to implement this. Here's my idea how it should work:
-
if the
--default-config
flag is used, use the default configuration -
otherwise, if the
--config
argument is used, look for a configuration file at the specified path -
otherwise, if the
DUNESH_CONFIG
environment variable is set, look for a configuration file at the specified path -
if the specified path specified is a
toml
orjson
file, use it for configuration. Otherwise, show an error and proceed with the next step. -
call
dirs_next::config_dir()
to find the path where config files should be stored- if it returns
None
, use the default configuration - otherwise, look for a
./dunesh/config.toml
or./dunesh/config.json
file within the config directory. If one of them exists, use it. If neither exist, use the default configuration. If both exist, use the default configuration and show an error.
- if it returns
-
if a configuration file was found, parse it as TOML or JSON, depending on the file ending. If that fails, show an error and use the default configuration
-
if the configuration file contains unsupported keys, show a warning
In the default configuration, ~/.dunesh_history
contains the command history and ~/.dunesh_prelude
contains the prelude.
Here's an example configuration file:
# Configuration file for dune shell
version = "0.1.7" # dunesh version for which this config file was created
extends = "default" # a path to another config file can be specified here
preludes = [
# the `~` is expanded to the home directory
# relative paths are resolved relative to this file
"~/dunesh/completions.dune",
"~/dunesh/abbreviations.dune",
"~/dunesh/util.dune",
"./docker_util.dune",
"/etc/**/prelude.dune"
]
history = "~/.dunesh_history"
use_shortcuts = "custom"
use_theme = "dark"
[shortcuts.custom]
extends = "default"
"ctrl+leftarrow" = "move_wb_left"
"ctrl+rightarrow" = "move_wb_right"
"page_up" = "move_start"
"escape" = "clear_input"
[shortcuts.vi.insert]
# configuration for vi shortcuts in "insert" mode
"ctrl+leftarrow" = "move_wb_left"
"ctrl+rightarrow" = "move_wb_right"
[themes.dark]
extends = "default_dark"
strings = "#ffcc77"
numbers = "#44aaff"
errors = { color = "#f55", bold = true }
operators = {} # don't use any color or style
I'll start implementing the things that already exist: Prelude(s) and history.