pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
    const HOME_SYMBOL: &str = "~";
    const DIR_TRUNCATION_LENGTH: i64 = 3;
    const FISH_STYLE_PWD_DIR_LENGTH: i64 = 0;

    let mut module = context.new_module("directory");
    let module_color = module
        .config_value_style("style")
        .unwrap_or_else(|| Color::Cyan.bold());
    module.set_style(module_color);

    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 fish_style_pwd_dir_length = module
        .config_value_i64("fish_style_pwd_dir_length")
        .unwrap_or(FISH_STYLE_PWD_DIR_LENGTH);

    let home_dir = dirs::home_dir().unwrap();
    let current_dir = &context.current_dir;
    log::debug!("Current directory: {:?}", current_dir);

    let repo = &context.get_repo().ok()?;

    let dir_string = match &repo.root {
        Some(repo_root) if truncate_to_repo => {
            let repo_folder_name = repo_root.file_name().unwrap().to_str().unwrap();

            // Contract the path to the git repo root
            contract_path(current_dir, repo_root, repo_folder_name)
        }
        // Contract the path to the home directory
        _ => 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);

    if fish_style_pwd_dir_length > 0 {
        // If user is using fish style path, we need to add the segment first
        let contracted_home_dir = contract_path(current_dir, &home_dir, HOME_SYMBOL);
        let fish_style_dir = to_fish_style(
            fish_style_pwd_dir_length as usize,
            contracted_home_dir,
            &truncated_dir_string,
        );

        module.new_segment("path", &fish_style_dir);
    }

    module.new_segment("path", &truncated_dir_string);

    module.get_prefix().set_value("in ");

    Some(module)
}
/// Creates a module with the current directory
///
/// Will perform path contraction and truncation.
/// **Contraction**
///     - Paths beginning with the home directory will be contracted to `~`
///     - Paths containing a git repo will contract to begin at the repo root
///
/// **Truncation**
/// Paths will be limited in length to `3` path components by default.
Creates a module with the current directory
Will perform path contraction and truncation.
Contraction
Paths beginning with the home directory will be contracted to `~`
Paths containing a git repo will contract to begin at the repo root

Truncation
Paths will be limited in length to `3` path components by default.
Creates a module with the current directory Will perform path contraction and truncation . Contraction Paths beginning with the home directory will be contracted to ` ~ ` Paths containing a git repo will contract to begin at the repo root Truncation Paths will be limited in length to ` 3 ` path components by default .
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
    const HOME_SYMBOL: &str = "~";
    const DIR_TRUNCATION_LENGTH: i64 = 3;
    const FISH_STYLE_PWD_DIR_LENGTH: i64 = 0;
    let mut module = context.new_module("directory");
    let module_color = module
        .config_value_style("style")
        .unwrap_or_else(|| Color::Cyan.bold());
    module.set_style(module_color);
    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 fish_style_pwd_dir_length = module
        .config_value_i64("fish_style_pwd_dir_length")
        .unwrap_or(FISH_STYLE_PWD_DIR_LENGTH);
    let home_dir = dirs::home_dir().unwrap();
    let current_dir = &context.current_dir;
    log::debug!("Current directory: {:?}", current_dir);
    let repo = &context.get_repo().ok()?;
    let dir_string = match &repo.root {
        Some(repo_root) if truncate_to_repo => {
            let repo_folder_name = repo_root.file_name().unwrap().to_str().unwrap();
            // Contract the path to the git repo root
            contract_path(current_dir, repo_root, repo_folder_name)
        }
        // Contract the path to the home directory
        _ => 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);
    if fish_style_pwd_dir_length > 0 {
        // If user is using fish style path, we need to add the segment first
        let contracted_home_dir = contract_path(current_dir, &home_dir, HOME_SYMBOL);
        let fish_style_dir = to_fish_style(
            fish_style_pwd_dir_length as usize,
            contracted_home_dir,
            &truncated_dir_string,
        );
        module.new_segment("path", &fish_style_dir);
    }
    module.new_segment("path", &truncated_dir_string);
    module.get_prefix().set_value("in ");
    Some(module)
}
pub fn module < ' a > ( context : & ' a Context ) -> Option < Module < ' a > > { const HOME_SYMBOL : & str = " " ; const DIR_TRUNCATION_LENGTH : i64 = 3 ; const FISH_STYLE_PWD_DIR_LENGTH : i64 = 0 ; let mut module = context . new_module ( " " ) ; let module_color = module . config_value_style ( " " ) . unwrap_or_else ( | | Color :: Cyan . bold ( ) ) ; module . set_style ( module_color ) ; let truncation_length = module . config_value_i64 ( " " ) . unwrap_or ( DIR_TRUNCATION_LENGTH ) ; let truncate_to_repo = module . config_value_bool ( " " ) . unwrap_or ( true ) ; let fish_style_pwd_dir_length = module . config_value_i64 ( " " ) . unwrap_or ( FISH_STYLE_PWD_DIR_LENGTH ) ; let home_dir = dirs :: home_dir ( ) . unwrap ( ) ; let current_dir = & context . current_dir ; log :: debug ! ( " " current_dir ) ; let repo = & context . get_repo ( ) . ok ( ) ? ; let dir_string = match & repo . root { Some ( repo_root ) if truncate_to_repo => { let repo_folder_name = repo_root . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ; // Contract the path to the git repo root contract_path ( current_dir , repo_root , repo_folder_name ) } // Contract the path to the home directory _ => 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 ) ; if fish_style_pwd_dir_length > 0 { // If user is using fish style path, we need to add the segment first let contracted_home_dir = contract_path ( current_dir , & home_dir , HOME_SYMBOL ) ; let fish_style_dir = to_fish_style ( fish_style_pwd_dir_length as usize , contracted_home_dir , & truncated_dir_string , ) ; module . new_segment ( " " , & fish_style_dir ) ; } module . new_segment ( " " , & truncated_dir_string ) ; module . get_prefix ( ) . set_value ( " " ) ; Some ( module ) }
Creates a module with the current directory
Will perform path contraction and truncation.
Creates a module with the current directory Will perform path contraction and truncation .
context
&'a Context