ui/conf: expand include() paths in config

Expand variables and `~` in included paths in user configuration.
master
Manos Pitsidianakis 2020-02-08 23:51:33 +02:00
parent 0b4109dfdb
commit cadb1e1613
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 8 additions and 10 deletions

View File

@ -602,6 +602,7 @@ mod pp {
use melib::{ use melib::{
error::{MeliError, Result}, error::{MeliError, Result},
parsec::*, parsec::*,
ShellExpandTrait,
}; };
use std::io::Read; use std::io::Read;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -682,19 +683,16 @@ mod pp {
l l
)) ))
})? { })? {
let p = &Path::new(sub_path); let mut p = Path::new(sub_path).expand();
debug!(p); if p.is_relative() {
let p_buf = if p.is_relative() {
/* We checked that path is ok above so we can do unwrap here */ /* We checked that path is ok above so we can do unwrap here */
debug!(path); debug!(path);
let prefix = path.parent().unwrap(); let prefix = path.parent().unwrap();
debug!(prefix); debug!(prefix);
prefix.join(p) p = prefix.join(p)
} else { }
p.to_path_buf()
};
ret.extend(pp_helper(&p_buf, level + 1)?.chars()); ret.extend(pp_helper(&p, level + 1)?.chars());
} else { } else {
ret.push_str(l); ret.push_str(l);
ret.push('\n'); ret.push('\n');
@ -708,9 +706,9 @@ mod pp {
/// in the filesystem. /// in the filesystem.
pub fn pp<P: AsRef<Path>>(path: P) -> Result<String> { pub fn pp<P: AsRef<Path>>(path: P) -> Result<String> {
let p_buf: PathBuf = if path.as_ref().is_relative() { let p_buf: PathBuf = if path.as_ref().is_relative() {
path.as_ref().canonicalize()? path.as_ref().expand().canonicalize()?
} else { } else {
path.as_ref().to_path_buf() path.as_ref().expand()
}; };
let mut ret = pp_helper(&p_buf, 0)?; let mut ret = pp_helper(&p_buf, 0)?;