summaryrefslogtreecommitdiffstats
path: root/src/modules/directory.rs
diff options
context:
space:
mode:
authorNeil Kistner <neil.kistner@gmail.com>2019-09-09 18:14:38 -0500
committerMatan Kushner <hello@matchai.me>2019-09-09 19:14:38 -0400
commit9f70ffb7a7d2eeef64c360c553e909d38e44adf0 (patch)
tree4dccf8a935e027dcf7bc77781eed1554a645d72a /src/modules/directory.rs
parentdc8409333e194624896c74c5e5cdb4f664f53f9d (diff)
fix: Lazy load git repo and only run module if not disabled (#306)
A couple of optimizations are done in this PR. One, we now will check config ahead of time to see if a module is disabled before running any module code. Also, we won't try to discover a git repository unless the module requests access to it.
Diffstat (limited to 'src/modules/directory.rs')
-rw-r--r--src/modules/directory.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/modules/directory.rs b/src/modules/directory.rs
index 952701262..096b07646 100644
--- a/src/modules/directory.rs
+++ b/src/modules/directory.rs
@@ -18,7 +18,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const DIR_TRUNCATION_LENGTH: i64 = 3;
const FISH_STYLE_PWD_DIR_LENGTH: i64 = 0;
- let mut module = context.new_module("directory")?;
+ let mut module = context.new_module("directory");
let module_color = module
.config_value_style("style")
.unwrap_or_else(|| Color::Cyan.bold());
@@ -36,7 +36,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let current_dir = &context.current_dir;
log::debug!("Current directory: {:?}", current_dir);
- let dir_string = match &context.repo_root {
+ 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();