aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Cao <cao.joshua@yahoo.com>2024-07-02 12:14:25 -0700
committerGitHub <noreply@github.com>2024-07-02 19:14:25 +0000
commit5e6b92db85b3ea7ffd06a7a5ae0d2d62ad5946a6 (patch)
treeab37c6d2cd45de1868b65974d5f7d9bff2fe0973
parent138ac426bfeb73db4f00d13a9126527d02c1e867 (diff)
downloadalacritty-5e6b92db85b3ea7ffd06a7a5ae0d2d62ad5946a6.tar.gz
alacritty-5e6b92db85b3ea7ffd06a7a5ae0d2d62ad5946a6.zip
Support relative imports in config file
Co-authored-by: Christian Duerr <contact@christianduerr.com>
-rw-r--r--CHANGELOG.md4
-rw-r--r--alacritty/src/config/mod.rs18
-rw-r--r--alacritty/src/migrate.rs5
-rw-r--r--extra/man/alacritty.5.scd6
4 files changed, 26 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3d1bd0c8..97d3de84 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,10 @@ Notable changes to the `alacritty_terminal` crate are documented in its
## 0.14.0-dev
+### Added
+
+- Support relative path imports from config files
+
### Changed
- Pressing `Alt` with unicode input will now add `ESC` like for ASCII input
diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs
index f043d73b..488ef537 100644
--- a/alacritty/src/config/mod.rs
+++ b/alacritty/src/config/mod.rs
@@ -205,7 +205,7 @@ fn parse_config(
let config = deserialize_config(path, false)?;
// Merge config with imports.
- let imports = load_imports(&config, config_paths, recursion_limit);
+ let imports = load_imports(&config, path, config_paths, recursion_limit);
Ok(serde_utils::merge(imports, config))
}
@@ -237,9 +237,14 @@ pub fn deserialize_config(path: &Path, warn_pruned: bool) -> Result<Value> {
}
/// Load all referenced configuration files.
-fn load_imports(config: &Value, config_paths: &mut Vec<PathBuf>, recursion_limit: usize) -> Value {
+fn load_imports(
+ config: &Value,
+ base_path: &Path,
+ config_paths: &mut Vec<PathBuf>,
+ recursion_limit: usize,
+) -> Value {
// Get paths for all imports.
- let import_paths = match imports(config, recursion_limit) {
+ let import_paths = match imports(config, base_path, recursion_limit) {
Ok(import_paths) => import_paths,
Err(err) => {
error!(target: LOG_TARGET_CONFIG, "{err}");
@@ -278,6 +283,7 @@ fn load_imports(config: &Value, config_paths: &mut Vec<PathBuf>, recursion_limit
/// Get all import paths for a configuration.
pub fn imports(
config: &Value,
+ base_path: &Path,
recursion_limit: usize,
) -> StdResult<Vec<StdResult<PathBuf, String>>, String> {
let imports = match config.get("import") {
@@ -307,6 +313,12 @@ pub fn imports(
path = home_dir.join(stripped);
}
+ if path.is_relative() {
+ if let Some(base_path) = base_path.parent() {
+ path = base_path.join(path)
+ }
+ }
+
import_paths.push(Ok(path));
}
diff --git a/alacritty/src/migrate.rs b/alacritty/src/migrate.rs
index dbcfb2ae..6d116858 100644
--- a/alacritty/src/migrate.rs
+++ b/alacritty/src/migrate.rs
@@ -81,7 +81,7 @@ fn migrate_config(
// Migrate config imports.
if !options.skip_imports {
- migrate_imports(options, &mut config, recursion_limit)?;
+ migrate_imports(options, &mut config, path, recursion_limit)?;
}
// Migrate deprecated field names to their new location.
@@ -110,9 +110,10 @@ fn migrate_config(
fn migrate_imports(
options: &MigrateOptions,
config: &mut Value,
+ base_path: &Path,
recursion_limit: usize,
) -> Result<(), String> {
- let imports = match config::imports(config, recursion_limit) {
+ let imports = match config::imports(config, base_path, recursion_limit) {
Ok(imports) => imports,
Err(err) => return Err(format!("import error: {err}")),
};
diff --git a/extra/man/alacritty.5.scd b/extra/man/alacritty.5.scd
index 1b56210b..15bc2127 100644
--- a/extra/man/alacritty.5.scd
+++ b/extra/man/alacritty.5.scd
@@ -35,13 +35,15 @@ This section documents the root level of the configuration file.
file being loaded last. If a field is already present in a previous import,
it will be replaced.
- All imports must either be absolute paths starting with _/_, or paths
- relative to the user's home directory starting with _~/_.
+ All imports must either be absolute paths starting with _/_, paths relative
+ to the user's home directory starting with _~/_, or paths relative from the
+ current config file.
Example:
import = [++
_"~/.config/alacritty/base16-dark.toml"_,++
_"~/.config/alacritty/keybindings.toml"_,++
+ _"alacritty-theme/themes/gruvbox_dark.toml"_,++
]
*shell* = _"<string>"_ | { program = _"<string>"_, args = [_"<string>"_,] }