-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable visit all the folders/file inside the zet repository
- Loading branch information
1 parent
4cd9bc4
commit 500c307
Showing
4 changed files
with
66 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::{ | ||
env, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
/// Retrieve the current dir for Zettelkasten notes | ||
/// | ||
/// 1. $ZET_PATH | ||
/// 2. $HOME/.config/zet | ||
/// | ||
/// This function is not portable, the .config folder will not work on windows | ||
pub fn dir() -> PathBuf { | ||
let mut path = match env::var("ZET_PATH") { | ||
Ok(val) => String::from(val), | ||
Err(_e) => "".to_string(), | ||
}; | ||
|
||
if path.is_empty() { | ||
let home = match env::var("HOME") { | ||
Ok(val) => String::from(val), | ||
Err(_e) => panic!("doesn't have $HOME env set"), // TODO: this should not be a problem | ||
// for windows :( | ||
}; | ||
|
||
path = format!("{home}/.config/zet"); | ||
} | ||
|
||
return Path::new(&path).to_path_buf(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::{ | ||
fs::{self}, | ||
io, | ||
path::PathBuf, | ||
}; | ||
|
||
pub fn run() -> io::Result<()> { | ||
let _ = visit_dirs(&zet::dir()); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn visit_dirs(dir: &PathBuf) -> io::Result<()> { | ||
if dir.is_dir() { | ||
for entry in fs::read_dir(dir)? { | ||
let entry = entry?; | ||
let path = entry.path(); | ||
println!("{:?}", path); | ||
if path.is_dir() { | ||
visit_dirs(&path)?; | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} |