From 5dbf4381acd1fd8dbb2905828c3fcc6515d850cf Mon Sep 17 00:00:00 2001 From: Andrew Dassonville Date: Sun, 28 Jul 2019 18:05:13 -0700 Subject: feat: Allow directory truncation length to be configured (#120) This allows the directory truncation length to be configured. Previously, it was hard-coded to truncate to 3 parent directories. --- src/modules/directory.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/modules/directory.rs') diff --git a/src/modules/directory.rs b/src/modules/directory.rs index 61937e751..a14f1c204 100644 --- a/src/modules/directory.rs +++ b/src/modules/directory.rs @@ -15,12 +15,16 @@ use super::{Context, Module}; /// Paths will be limited in length to `3` path components by default. pub fn module<'a>(context: &'a Context) -> Option> { const HOME_SYMBOL: &str = "~"; - const DIR_TRUNCATION_LENGTH: usize = 3; + const DIR_TRUNCATION_LENGTH: i64 = 3; let module_color = Color::Cyan.bold(); let mut module = context.new_module("directory")?; module.set_style(module_color); + let truncation_length = module + .config_value_i64("truncation_length") + .unwrap_or(DIR_TRUNCATION_LENGTH); + let current_dir = &context.current_dir; log::debug!("Current directory: {:?}", current_dir); @@ -38,7 +42,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { } // Truncate the dir string to the maximum number of path components - let truncated_dir_string = truncate(dir_string, DIR_TRUNCATION_LENGTH); + let truncated_dir_string = truncate(dir_string, truncation_length as usize); module.new_segment("path", &truncated_dir_string); module.get_prefix().set_value("in "); -- cgit v1.2.3