Skip to content

Commit 07cfe8b

Browse files
authored
Add support for '~/' in config imports
This allows the configuration file imports to start with '~/' and resolve relative to the user's home directory. There is no support for '~user/' or '$HOME/' or any other shell expansion. However since paths relative to the home directory should be sufficient for everything, this provides a very simple solution without any significant drawbacks. Fixes alacritty#4157.
1 parent da6f0a5 commit 07cfe8b

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77

88
## 0.7.0-dev
99

10+
### Added
11+
12+
- Support for `~/` at the beginning of configuration file imports
13+
1014
### Changed
1115

1216
- Nonexistent config imports are ignored instead of raising an error

Diff for: Cargo.lock

+11-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: alacritty.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
# Import additional configuration files
44
#
5-
# These configuration files will be loaded in order, replacing values in files
6-
# loaded earlier with those loaded later in the chain. The file itself will
7-
# always be loaded last. If an import path cannot be found it will be skipped.
5+
# Imports are loaded in order, skipping all missing files, with the importing
6+
# file being loaded last. If a field is already present in a previous import, it
7+
# will be replaced.
8+
#
9+
# All imports must either be absolute paths starting with `/`, or paths relative
10+
# to the user's home directory starting with `~/`.
811
#import:
912
# - /path/to/alacritty.yml
1013

Diff for: alacritty/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ copypasta = { version = "0.7.0", default-features = false }
3030
libc = "0.2"
3131
unicode-width = "0.1"
3232
bitflags = "1"
33+
dirs = "2.0.2"
3334

3435
[build-dependencies]
3536
gl_generator = "0.14.0"
@@ -43,9 +44,6 @@ image = { version = "0.23.3", default-features = false, features = ["ico"], opti
4344
[target.'cfg(target_os = "macos")'.dependencies]
4445
objc = "0.2.2"
4546

46-
[target.'cfg(any(target_os = "macos", windows))'.dependencies]
47-
dirs = "2.0.2"
48-
4947
[target.'cfg(not(any(target_os="windows", target_os="macos")))'.dependencies]
5048
x11-dl = { version = "2", optional = true }
5149
wayland-client = { version = "0.28.0", features = ["dlopen"], optional = true }

Diff for: alacritty/src/config/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ fn load_imports(config: &Value, config_paths: &mut Vec<PathBuf>, recursion_limit
211211
let mut merged = Value::Null;
212212

213213
for import in imports {
214-
let path = match import {
214+
let mut path = match import {
215215
Value::String(path) => PathBuf::from(path),
216216
_ => {
217217
error!(
@@ -222,6 +222,11 @@ fn load_imports(config: &Value, config_paths: &mut Vec<PathBuf>, recursion_limit
222222
},
223223
};
224224

225+
// Resolve paths relative to user's home directory.
226+
if let (Ok(stripped), Some(home_dir)) = (path.strip_prefix("~/"), dirs::home_dir()) {
227+
path = home_dir.join(stripped);
228+
}
229+
225230
if !path.exists() {
226231
info!(target: LOG_TARGET_CONFIG, "Skipping importing config; not found:");
227232
info!(target: LOG_TARGET_CONFIG, " {:?}", path.display());

0 commit comments

Comments
 (0)