diff options
author | Saghm Rossi <saghmrossi@gmail.com> | 2019-08-16 23:29:22 -0400 |
---|---|---|
committer | Kevin Song <chipbuster@users.noreply.github.com> | 2019-08-16 20:29:22 -0700 |
commit | 84c394e7b054391e07a571b713816d7d357e7c75 (patch) | |
tree | b5f14484f2977396f79706917f96fce7e306c2ad /src | |
parent | d065dff695b22fe04d56b89f45a1550bdd93c303 (diff) |
feat: Add option to control git directory truncation (#165)
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/directory.rs | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/modules/directory.rs b/src/modules/directory.rs index 51c776e40..ee3924b98 100644 --- a/src/modules/directory.rs +++ b/src/modules/directory.rs @@ -24,22 +24,26 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let truncation_length = module .config_value_i64("truncation_length") .unwrap_or(DIR_TRUNCATION_LENGTH); + let truncate_to_repo = module.config_value_bool("truncate_to_repo").unwrap_or(true); let current_dir = &context.current_dir; log::debug!("Current directory: {:?}", current_dir); let dir_string; - if let Some(repo_root) = &context.repo_root { - // Contract the path to the git repo root - let repo_folder_name = repo_root.file_name().unwrap().to_str().unwrap(); - - dir_string = contract_path(current_dir, repo_root, repo_folder_name); - } else { - // Contract the path to the home directory - let home_dir = dirs::home_dir().unwrap(); - - dir_string = contract_path(current_dir, &home_dir, HOME_SYMBOL); - } + match &context.repo_root { + Some(repo_root) if truncate_to_repo => { + // Contract the path to the git repo root + let repo_folder_name = repo_root.file_name().unwrap().to_str().unwrap(); + + dir_string = contract_path(current_dir, repo_root, repo_folder_name); + } + _ => { + // Contract the path to the home directory + let home_dir = dirs::home_dir().unwrap(); + + dir_string = contract_path(current_dir, &home_dir, HOME_SYMBOL); + } + }; // Truncate the dir string to the maximum number of path components let truncated_dir_string = truncate(dir_string, truncation_length as usize); |