1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Resolves shell tilde paths to absolute system paths.
//!
//! This module provides the functionality to replace the `~` symbol at the beginning of a path
//! with the actual path of the user's home directory ($HOME).
/**
* expand_path.rs
*
* (C) Copyright 2026 AtlantisOS Project
* by @NachtsternBuild
*
* License: GNU GENERAL PUBLIC LICENSE Version 3
*/
use env;
use ;
/// Replaces a leading tilde (`~`) with the path from the `$HOME` environment variable.
///
/// If the path does not start with a tilde or the `$HOME` environment variable
/// is not set, the original path is returned unchanged.
///
/// # How it works
/// 1. Checks if the path starts with `~`.
/// 2. Reads `$HOME` from the operating system's environment variables.
/// 3. Removes the tilde and concatenates the rest of the path with the home directory.
///
/// # Arguments
/// * `path` - The path to be resolved (accepts `&str`, `String`, `Path`, etc.).
///
/// # Return Value
/// A [PathBuf] containing the absolute path (if successful) or the original path.
///
/// # Usage:
///
/// ```rust
/// fn main() {
/// let local_conf = "~/config/settings.toml";
/// let expanded = expand_path(local_conf);
/// println!("Original: {}", local_conf);
/// println!("Expanded: {:?}", expanded);
/// }
/// ```