pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
    let mut module = context.new_module("directory");
    let config: DirectoryConfig = DirectoryConfig::try_load(module.config);

    let current_dir = &get_current_dir(&context, &config);

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

    let repo = &context.get_repo().ok()?;
    let dir_string = match &repo.root {
        Some(repo_root) if config.truncate_to_repo && (repo_root != &home_dir) => {
            log::debug!("Repo root: {:?}", repo_root);
            // Contract the path to the git repo root
            contract_repo_path(current_dir, repo_root)
                .unwrap_or_else(|| contract_path(current_dir, &home_dir, HOME_SYMBOL))
        }
        // Contract the path to the home directory
        _ => contract_path(current_dir, &home_dir, HOME_SYMBOL),
    };
    log::debug!("Dir string: {}", dir_string);

    let substituted_dir = substitute_path(dir_string, &config.substitutions);

    // Truncate the dir string to the maximum number of path components
    let truncated_dir_string = truncate(substituted_dir, config.truncation_length as usize);

    let prefix = if is_truncated(&truncated_dir_string) {
        // Substitutions could have changed the prefix, so don't allow them and
        // fish-style path contraction together
        if config.fish_style_pwd_dir_length > 0 && config.substitutions.is_empty() {
            // 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);
            to_fish_style(
                config.fish_style_pwd_dir_length as usize,
                contracted_home_dir,
                &truncated_dir_string,
            )
        } else {
            String::from(config.truncation_symbol)
        }
    } else {
        String::from("")
    };

    let displayed_path = prefix + &truncated_dir_string;
    let lock_symbol = String::from(config.read_only);

    let parsed = StringFormatter::new(config.format).and_then(|formatter| {
        formatter
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                "read_only_style" => Some(Ok(config.read_only_style)),
                _ => None,
            })
            .map(|variable| match variable {
                "path" => Some(Ok(&displayed_path)),
                "read_only" => {
                    if is_readonly_dir(&context.current_dir) {
                        Some(Ok(&lock_symbol))
                    } else {
                        None
                    }
                }
                _ => None,
            })
            .parse(None)
    });

    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `directory`:\n{}", error);
            return None;
        }
    });

    Some(module)
}
/// Creates a module with the current directory
///
/// Will perform path contraction, substitution, and truncation.
///
/// **Contraction**
///
/// - Paths beginning with the home directory or with a git repo right inside
///   the home directory will be contracted to `~`
/// - Paths containing a git repo will contract to begin at the repo root
///
/// **Substitution**
/// Paths will undergo user-provided substitutions of substrings
///
/// **Truncation**
/// Paths will be limited in length to `3` path components by default.
Creates a module with the current directory
Will perform path contraction, substitution, and truncation.

Contraction

Paths beginning with the home directory or with a git repo right inside
the home directory will be contracted to `~`
Paths containing a git repo will contract to begin at the repo root

Substitution
Paths will undergo user-provided substitutions of substrings

Truncation
Paths will be limited in length to `3` path components by default.
Creates a module with the current directory Will perform path contraction substitution and truncation . Contraction Paths beginning with the home directory or with a git repo right inside the home directory will be contracted to ` ~ ` Paths containing a git repo will contract to begin at the repo root Substitution Paths will undergo user - provided substitutions of substrings Truncation Paths will be limited in length to ` 3 ` path components by default .
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
    let mut module = context.new_module("directory");
    let config: DirectoryConfig = DirectoryConfig::try_load(module.config);
    let current_dir = &get_current_dir(&context, &config);
    let home_dir = dirs_next::home_dir().unwrap();
    log::debug!("Current directory: {:?}", current_dir);
    let repo = &context.get_repo().ok()?;
    let dir_string = match &repo.root {
        Some(repo_root) if config.truncate_to_repo && (repo_root != &home_dir) => {
            log::debug!("Repo root: {:?}", repo_root);
            // Contract the path to the git repo root
            contract_repo_path(current_dir, repo_root)
                .unwrap_or_else(|| contract_path(current_dir, &home_dir, HOME_SYMBOL))
        }
        // Contract the path to the home directory
        _ => contract_path(current_dir, &home_dir, HOME_SYMBOL),
    };
    log::debug!("Dir string: {}", dir_string);
    let substituted_dir = substitute_path(dir_string, &config.substitutions);
    // Truncate the dir string to the maximum number of path components
    let truncated_dir_string = truncate(substituted_dir, config.truncation_length as usize);
    let prefix = if is_truncated(&truncated_dir_string) {
        // Substitutions could have changed the prefix, so don't allow them and
        // fish-style path contraction together
        if config.fish_style_pwd_dir_length > 0 && config.substitutions.is_empty() {
            // 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);
            to_fish_style(
                config.fish_style_pwd_dir_length as usize,
                contracted_home_dir,
                &truncated_dir_string,
            )
        } else {
            String::from(config.truncation_symbol)
        }
    } else {
        String::from("")
    };
    let displayed_path = prefix + &truncated_dir_string;
    let lock_symbol = String::from(config.read_only);
    let parsed = StringFormatter::new(config.format).and_then(|formatter| {
        formatter
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                "read_only_style" => Some(Ok(config.read_only_style)),
                _ => None,
            })
            .map(|variable| match variable {
                "path" => Some(Ok(&displayed_path)),
                "read_only" => {
                    if is_readonly_dir(&context.current_dir) {
                        Some(Ok(&lock_symbol))
                    } else {
                        None
                    }
                }
                _ => None,
            })
            .parse(None)
    });
    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `directory`:\n{}", error);
            return None;
        }
    });
    Some(module)
}
pub fn module < ' a > ( context : & ' a Context ) -> Option < Module < ' a > > { let mut module = context . new_module ( " " ) ; let config : DirectoryConfig = DirectoryConfig :: try_load ( module . config ) ; let current_dir = & get_current_dir ( & context , & config ) ; let home_dir = dirs_next :: home_dir ( ) . unwrap ( ) ; log :: debug ! ( " " current_dir ) ; let repo = & context . get_repo ( ) . ok ( ) ? ; let dir_string = match & repo . root { Some ( repo_root ) if config . truncate_to_repo && ( repo_root != & home_dir ) => { log :: debug ! ( " " repo_root ) ; // Contract the path to the git repo root contract_repo_path ( current_dir , repo_root ) . unwrap_or_else ( | | contract_path ( current_dir , & home_dir , HOME_SYMBOL ) ) } // Contract the path to the home directory _ => contract_path ( current_dir , & home_dir , HOME_SYMBOL ) , } ; log :: debug ! ( " " dir_string ) ; let substituted_dir = substitute_path ( dir_string , & config . substitutions ) ; // Truncate the dir string to the maximum number of path components let truncated_dir_string = truncate ( substituted_dir , config . truncation_length as usize ) ; let prefix = if is_truncated ( & truncated_dir_string ) { // Substitutions could have changed the prefix, so don't allow them and // fish-style path contraction together if config . fish_style_pwd_dir_length > 0 && config . substitutions . is_empty ( ) { // 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 ) ; to_fish_style ( config . fish_style_pwd_dir_length as usize , contracted_home_dir , & truncated_dir_string , ) } else { String :: from ( config . truncation_symbol ) } } else { String :: from ( " " ) } ; let displayed_path = prefix + & truncated_dir_string ; let lock_symbol = String :: from ( config . read_only ) ; let parsed = StringFormatter :: new ( config . format ) . and_then ( | formatter | { formatter . map_style ( | variable | match variable { " " => Some ( Ok ( config . style ) ) , " " => Some ( Ok ( config . read_only_style ) ) , _ => None , } ) . map ( | variable | match variable { " " => Some ( Ok ( & displayed_path ) ) , " " => { if is_readonly_dir ( & context . current_dir ) { Some ( Ok ( & lock_symbol ) ) } else { None } } _ => None , } ) . parse ( None ) } ) ; module . set_segments ( match parsed { Ok ( segments ) => segments , Err ( error ) => { log :: warn ! ( " \n " error ) ; return None ; } } ) ; Some ( module ) }
Creates a module with the current directory
Will perform path contraction, substitution, and truncation.
Creates a module with the current directory Will perform path contraction substitution and truncation .
context
&'a Context