Skip to content

Commit

Permalink
Replace ~ by $HOME (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Jun 15, 2021
1 parent 2c6620f commit 4c9583b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 39 deletions.
71 changes: 34 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::structures::cheat::VariableMap;
use crate::structures::fetcher;
use anyhow::Result;
use directories_next::BaseDirs;
use regex::Regex;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;
Expand Down Expand Up @@ -127,8 +128,15 @@ impl fetcher::Fetcher for Fetcher {
let paths = paths.expect("Unable to get paths");
let folders = paths_from_path_param(&paths);

let home_regex = Regex::new(r"^~").unwrap();
let home = BaseDirs::new().and_then(|b| pathbuf_to_string(b.home_dir()).ok());

for folder in folders {
let folder_pathbuf = PathBuf::from(folder);
let interpolated_folder = match &home {
Some(h) => home_regex.replace(folder, h).to_string(),
None => folder.to_string(),
};
let folder_pathbuf = PathBuf::from(interpolated_folder);
for file in all_cheat_files(&folder_pathbuf) {
files.push(file.clone());
let index = files.len() - 1;
Expand Down
4 changes: 3 additions & 1 deletion tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ fi

_navi() {
stty sane || true
RUST_BACKTRACE=1 NAVI_PATH="${NAVI_TEST_PATH:-$TEST_CHEAT_PATH}" "$NAVI_EXE" "$@"
local path="${NAVI_TEST_PATH:-$TEST_CHEAT_PATH}"
path="${path//$HOME/~}"
RUST_BACKTRACE=1 NAVI_PATH="$path" "$NAVI_EXE" "$@"
}

_navi_cases() {
Expand Down

0 comments on commit 4c9583b

Please sign in to comment.