summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--Cargo.lock8
-rw-r--r--Cargo.toml2
-rw-r--r--src/context.rs80
-rw-r--r--src/modules/battery.rs2
-rw-r--r--src/modules/character.rs2
-rw-r--r--src/modules/cmd_duration.rs2
-rw-r--r--src/modules/directory.rs6
-rw-r--r--src/modules/git_branch.rs5
-rw-r--r--src/modules/git_state.rs41
-rw-r--r--src/modules/git_status.rs13
-rw-r--r--src/modules/golang.rs2
-rw-r--r--src/modules/hostname.rs2
-rw-r--r--src/modules/jobs.rs2
-rw-r--r--src/modules/line_break.rs2
-rw-r--r--src/modules/nix_shell.rs2
-rw-r--r--src/modules/nodejs.rs2
-rw-r--r--src/modules/package.rs2
-rw-r--r--src/modules/python.rs2
-rw-r--r--src/modules/ruby.rs2
-rw-r--r--src/modules/rust.rs2
-rw-r--r--src/modules/username.rs2
-rw-r--r--src/print.rs1
-rw-r--r--tests/testsuite/cmd_duration.rs17
-rw-r--r--tests/testsuite/common.rs9
-rw-r--r--tests/testsuite/configuration.rs14
-rw-r--r--tests/testsuite/git_branch.rs1
-rw-r--r--tests/testsuite/git_status.rs1
-rw-r--r--tests/testsuite/golang.rs23
-rw-r--r--tests/testsuite/jobs.rs16
-rw-r--r--tests/testsuite/nodejs.rs23
30 files changed, 111 insertions, 177 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1e3c89546..f5d04fc84 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -467,6 +467,11 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "once_cell"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "openssl-probe"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -756,8 +761,8 @@ dependencies = [
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"gethostname 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "once_cell 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"path-slash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_env_logger 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1031,6 +1036,7 @@ dependencies = [
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba"
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
+"checksum once_cell 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a04cb71e910d0034815600180f62a95bf6e67942d7ab52a166a68c7d7e9cd0"
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
"checksum openssl-sys 0.9.46 (registry+https://github.com/rust-lang/crates.io-index)" = "05636e06b4f8762d4b81d24a351f3966f38bd25ccbcfd235606c91fdb82cc60f"
"checksum path-slash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a0858af4d9136275541f4eac7be1af70add84cf356d901799b065ac1b8ff6e2f"
diff --git a/Cargo.toml b/Cargo.toml
index 8af9c8983..93272f108 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -37,10 +37,10 @@ log = "0.4.8"
# battery is optional (on by default) because the crate doesn't currently build for Termux
# see: https://github.com/svartalf/rust-battery/issues/33
battery = { version = "0.7.4", optional = true }
-lazy_static = "1.4.0"
path-slash = "0.1.1"
unicode-segmentation = "1.3.0"
gethostname = "0.2.0"
+once_cell = "1.1.0"
[dev-dependencies]
tempfile = "3.1.0"
diff --git a/src/context.rs b/src/context.rs
index 6ccda8495..836a18dbb 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -2,11 +2,12 @@ use crate::config::Config;
use crate::module::Module;
use clap::ArgMatches;
-use git2::Repository;
+use git2::{Repository, RepositoryState};
+use once_cell::sync::OnceCell;
use std::env;
use std::ffi::OsStr;
use std::fs;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
/// Context contains data or common methods that may be used by multiple modules.
/// The data contained within Context will be relevant to this particular rendering
@@ -24,13 +25,8 @@ pub struct Context<'a> {
/// The map of arguments that were passed when starship was called.
pub arguments: ArgMatches<'a>,
- /// If `current_dir` is a git repository or is contained within one,
- /// this is the path to the root of that repo.
- pub repo_root: Option<PathBuf>,
-
- /// If `current_dir` is a git repository or is contained within one,
- /// this is the current branch name of that repo.
- pub branch_name: Option<String>,
+ /// Private field to store Git information for modules who need it
+ repo: OnceCell<Repo>,
}
impl<'a> Context<'a> {
@@ -67,21 +63,12 @@ impl<'a> Context<'a> {
.map(|entry| entry.path())
.collect::<Vec<PathBuf>>();
- let repository = Repository::discover(&current_dir).ok();
- let repo_root = repository
- .as_ref()
- .and_then(|repo| repo.workdir().map(std::path::Path::to_path_buf));
- let branch_name = repository
- .as_ref()
- .and_then(|repo| get_current_branch(repo));
-
Context {
config,
arguments,
current_dir,
dir_files,
- repo_root,
- branch_name,
+ repo: OnceCell::new(),
}
}
@@ -95,20 +82,20 @@ impl<'a> Context<'a> {
}
/// Create a new module
- ///
- /// Will return `None` if the module is disabled by configuration, by setting
- /// the `disabled` key to `true` in the configuration for that module.
- pub fn new_module(&self, name: &str) -> Option<Module> {
+ pub fn new_module(&self, name: &str) -> Module {
+ let config = self.config.get_module_config(name);
+
+ Module::new(name, config)
+ }
+
+ /// Check the `disabled` configuration of the module
+ pub fn is_module_enabled(&self, name: &str) -> bool {
let config = self.config.get_module_config(name);
// If the segment has "disabled" set to "true", don't show it
let disabled = config.and_then(|table| table.get_as_bool("disabled"));
- if disabled == Some(true) {
- return None;
- }
-
- Some(Module::new(name, config))
+ disabled != Some(true)
}
// returns a new ScanDir struct with reference to current dir_files of context
@@ -121,6 +108,43 @@ impl<'a> Context<'a> {
extensions: &[],
}
}
+
+ /// Will lazily get repo root and branch when a module requests it.
+ pub fn get_repo(&self) -> Result<&Repo, std::io::Error> {
+ let repo = self
+ .repo
+ .get_or_try_init(|| -> Result<Repo, std::io::Error> {
+ let repository = Repository::discover(&self.current_dir).ok();
+ let branch = repository
+ .as_ref()
+ .and_then(|repo| get_current_branch(repo));
+ let root = repository
+ .as_ref()
+ .and_then(|repo| repo.workdir().map(Path::to_path_buf));
+ let state = repository.as_ref().map(|repo| repo.state());
+
+ Ok(Repo {
+ branch,
+ root,
+ state,
+ })
+ })?;
+
+ Ok(repo)
+ }
+}
+
+pub struct Repo {
+ /// If `current_dir` is a git repository or is contained within one,
+ /// this is the current branch name of that repo.
+ pub branch: Option<String>,
+
+ /// If `current_dir` is a git repository or is contained within one,
+ /// this is the path to the root of that repo.
+ pub root: Option<PathBuf>,
+
+ /// State
+ pub state: Option<RepositoryState>,
}
// A struct of Criteria which will be used to verify current PathBuf is
diff --git a/src/modules/battery.rs b/src/modules/battery.rs
index 47c9eee73..81edfbf0b 100644
--- a/src/modules/battery.rs
+++ b/src/modules/battery.rs
@@ -29,7 +29,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
// TODO: Set style based on percentage when threshold is modifiable
- let mut module = context.new_module("battery")?;
+ let mut module = context.new_module("battery");
let module_style = module
.config_value_style("style")
.unwrap_or_else(|| Color::Red.bold());
diff --git a/src/modules/character.rs b/src/modules/character.rs
index 704fe5c9f..9385e53c9 100644
--- a/src/modules/character.rs
+++ b/src/modules/character.rs
@@ -20,7 +20,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const ASSUMED_MODE: ShellEditMode = ShellEditMode::Insert;
// TODO: extend config to more modes
- let mut module = context.new_module("character")?;
+ let mut module = context.new_module("character");
module.get_prefix().set_value("");
let style_success = module
diff --git a/src/modules/cmd_duration.rs b/src/modules/cmd_duration.rs
index ac7102284..35a7e6858 100644
--- a/src/modules/cmd_duration.rs
+++ b/src/modules/cmd_duration.rs
@@ -7,7 +7,7 @@ use super::{Context, Module};
/// Will only print if last command took more than a certain amount of time to
/// execute. Default is two seconds, but can be set by config option `min_time`.
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
- let mut module = context.new_module("cmd_duration")?;
+ let mut module = context.new_module("cmd_duration");
let arguments = &context.arguments;
let elapsed = arguments
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();
diff --git a/src/modules/git_branch.rs b/src/modules/git_branch.rs
index d6b64c4e0..6d07e8905 100644
--- a/src/modules/git_branch.rs
+++ b/src/modules/git_branch.rs
@@ -9,7 +9,7 @@ use super::{Context, Module};
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const GIT_BRANCH_CHAR: &str = "๎‚  ";
- let mut module = context.new_module("git_branch")?;
+ let mut module = context.new_module("git_branch");
let segment_color = module
.config_value_style("style")
@@ -38,7 +38,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
} else {
unsafe_truncation_length as usize
};
- let branch_name = context.branch_name.as_ref()?;
+ let repo = context.get_repo().ok()?;
+ let branch_name = repo.branch.as_ref()?;
let truncated_graphemes = get_graphemes(&branch_name, len);
// The truncation symbol should only be added if we truncated
let truncated_and_symbol = if len < graphemes_len(&branch_name) {
diff --git a/src/modules/git_state.rs b/src/modules/git_state.rs
index 8d242b0ca..c26a6007b 100644
--- a/src/modules/git_state.rs
+++ b/src/modules/git_state.rs
@@ -1,6 +1,6 @@
use ansi_term::Color;
-use git2::{Repository, RepositoryState};
-use std::path::Path;
+use git2::RepositoryState;
+use std::path::{Path, PathBuf};
use super::{Context, Module};
@@ -9,11 +9,12 @@ use super::{Context, Module};
/// During a git operation it will show: REBASING, BISECTING, MERGING, etc.
/// If the progress information is available (e.g. rebasing 3/10), it will show that too.
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
- let mut module = context.new_module("git_state")?;
+ let mut module = context.new_module("git_state");
- let repo_root = context.repo_root.as_ref()?;
- let mut repository = Repository::open(repo_root).ok()?;
- let state_description = get_state_description(&mut repository);
+ let repo = context.get_repo().ok()?;
+ let repo_root = repo.root.as_ref()?;
+ let repo_state = repo.state?;
+ let state_description = get_state_description(repo_state, repo_root);
if let StateDescription::Clean = state_description {
return None;
@@ -79,8 +80,11 @@ static AM_OR_REBASE_LABEL: StateLabel = StateLabel {
message_default: "AM/REBASE",
};
-fn get_state_description(repository: &mut Repository) -> StateDescription {
- match repository.state() {
+/// Returns the state of the current repository
+///
+/// During a git operation it will show: REBASING, BISECTING, MERGING, etc.
+fn get_state_description(state: RepositoryState, root: &PathBuf) -> StateDescription {
+ match state {
RepositoryState::Clean => StateDescription::Clean,
RepositoryState::Merge => StateDescription::Label(&MERGE_LABEL),
RepositoryState::Revert => StateDescription::Label(&REVERT_LABEL),
@@ -90,13 +94,13 @@ fn get_state_description(repository: &mut Repository) -> StateDescription {
RepositoryState::Bisect => StateDescription::Label(&BISECT_LABEL),
RepositoryState::ApplyMailbox => StateDescription::Label(&AM_LABEL),
RepositoryState::ApplyMailboxOrRebase => StateDescription::Label(&AM_OR_REBASE_LABEL),
- RepositoryState::Rebase => describe_rebase(repository),
- RepositoryState::RebaseInteractive => describe_rebase(repository),
- RepositoryState::RebaseMerge => describe_rebase(repository),
+ RepositoryState::Rebase => describe_rebase(root),
+ RepositoryState::RebaseInteractive => describe_rebase(root),
+ RepositoryState::RebaseMerge => describe_rebase(root),
}
}
-fn describe_rebase(repository: &mut Repository) -> StateDescription {
+fn describe_rebase(root: &PathBuf) -> StateDescription {
/*
* Sadly, libgit2 seems to have some issues with reading the state of
* interactive rebases. So, instead, we'll poke a few of the .git files
@@ -107,18 +111,7 @@ fn describe_rebase(repository: &mut Repository) -> StateDescription {
let just_label = StateDescription::Label(&REBASE_LABEL);
- let dot_git = repository
- .workdir()
- .and_then(|d| Some(d.join(Path::new(".git"))));
-
- let dot_git = match dot_git {
- None => {
- // We didn't find the .git directory.
- // Something very odd is going on. We'll just back away slowly.
- return just_label;
- }
- Some(path) => path,
- };
+ let dot_git = root.join(".git");
let has_path = |relative_path: &str| {
let path = dot_git.join(Path::new(relative_path));
diff --git a/src/modules/git_status.rs b/src/modules/git_status.rs
index aa82fb739..badf0face 100644
--- a/src/modules/git_status.rs
+++ b/src/modules/git_status.rs
@@ -30,11 +30,12 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const GIT_STATUS_RENAMED: &str = "ยป";
const GIT_STATUS_DELETED: &str = "โœ˜";
- let branch_name = context.branch_name.as_ref()?;
- let repo_root = context.repo_root.as_ref()?;
+ let repo = context.get_repo().ok()?;
+ let branch_name = repo.branch.as_ref()?;
+ let repo_root = repo.root.as_ref()?;
let repository = Repository::open(repo_root).ok()?;
- let mut module = context.new_module("git_status")?;
+ let mut module = context.new_module("git_status");
let show_sync_count = module.config_value_bool("show_sync_count").unwrap_or(false);
let module_style = module
.config_value_style("style")
@@ -133,10 +134,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
if module.is_empty() {
- None
- } else {
- Some(module)
+ return None;
}
+
+ Some(module)
}
/// Gets the bitflags associated with the repo's git status
diff --git a/src/modules/golang.rs b/src/modules/golang.rs
index bf632bf72..4676f9e6d 100644
--- a/src/modules/golang.rs
+++ b/src/modules/golang.rs
@@ -29,7 +29,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
Some(go_version) => {
const GO_CHAR: &str = "๐Ÿน ";
- let mut module = context.new_module("golang")?;
+ let mut module = context.new_module("golang");
let module_style = module
.config_value_style("style")
.unwrap_or_else(|| Color::Cyan.bold());
diff --git a/src/modules/hostname.rs b/src/modules/hostname.rs
index 9b0690d8f..d71f733fa 100644
--- a/src/modules/hostname.rs
+++ b/src/modules/hostname.rs
@@ -10,7 +10,7 @@ use std::ffi::OsString;
/// - hostname.disabled is absent or false
/// - hostname.ssh_only is false OR the user is currently connected as an SSH session (`$SSH_CONNECTION`)
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
- let mut module = context.new_module("hostname")?;
+ let mut module = context.new_module("hostname");
let module_style = module
.config_value_style("style")
.unwrap_or_else(|| Color::Green.bold().dimmed());
diff --git a/src/modules/jobs.rs b/src/modules/jobs.rs
index bb8a2d7d4..8a667049e 100644
--- a/src/modules/jobs.rs
+++ b/src/modules/jobs.rs
@@ -4,7 +4,7 @@ use super::{Context, Module};
/// Creates a segment to show if there are any active jobs running
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
- let mut module = context.new_module("jobs")?;
+ let mut module = context.new_module("jobs");
let threshold = module.config_value_i64("threshold").unwrap_or(1);
diff --git a/src/modules/line_break.rs b/src/modules/line_break.rs
index 5cbe3a1a9..259e60877 100644
--- a/src/modules/line_break.rs
+++ b/src/modules/line_break.rs
@@ -4,7 +4,7 @@ use super::{Context, Module};
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const LINE_ENDING: &str = "\n";
- let mut module = context.new_module("line_break")?;
+ let mut module = context.new_module("line_break");
module.get_prefix().set_value("");
module.get_suffix().set_value("");
diff --git a/src/modules/nix_shell.rs b/src/modules/nix_shell.rs
index 5fc98dfc9..36228993d 100644
--- a/src/modules/nix_shell.rs
+++ b/src/modules/nix_shell.rs
@@ -22,7 +22,7 @@ use super::{Context, Module};
/// - pure // use_name == false in a pure nix-shell
/// - impure // use_name == false in an impure nix-shell
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
- let mut module = context.new_module("nix_shell")?;
+ let mut module = context.new_module("nix_shell");
env::var("IN_NIX_SHELL")
.ok()
diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs
index 8f8219c7a..180e143ff 100644
--- a/src/modules/nodejs.rs
+++ b/src/modules/nodejs.rs
@@ -25,7 +25,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
Some(node_version) => {
const NODE_CHAR: &str = "โฌข ";
- let mut module = context.new_module("nodejs")?;
+ let mut module = context.new_module("nodejs");
let module_style = module
.config_value_style("style")
.unwrap_or_else(|| Color::Green.bold());
diff --git a/src/modules/package.rs b/src/modules/package.rs
index ceb34bc6c..0debe162d 100644
--- a/src/modules/package.rs
+++ b/src/modules/package.rs
@@ -13,7 +13,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
Some(package_version) => {
const PACKAGE_CHAR: &str = "๐Ÿ“ฆ ";
- let mut module = context.new_module("package")?;
+ let mut module = context.new_module("package");
let module_style = module
.config_value_style("style")
.unwrap_or_else(|| Color::Red.bold());
diff --git a/src/modules/python.rs b/src/modules/python.rs
index 61d8189db..487d033d5 100644
--- a/src/modules/python.rs
+++ b/src/modules/python.rs
@@ -30,7 +30,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None;
}
- let mut module = context.new_module("python")?;
+ let mut module = context.new_module("python");
let pyenv_version_name = module
.config_value_bool("pyenv_version_name")
.unwrap_or(false);
diff --git a/src/modules/ruby.rs b/src/modules/ruby.rs
index a39bda75c..7e689234d 100644
--- a/src/modules/ruby.rs
+++ b/src/modules/ruby.rs
@@ -23,7 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
Some(ruby_version) => {
const RUBY_CHAR: &str = "๐Ÿ’Ž ";
- let mut module = context.new_module("ruby")?;
+ let mut module = context.new_module("ruby");
let module_style = module
.config_value_style("style")
.unwrap_or_else(|| Color::Red.bold());
diff --git a/src/modules/rust.rs b/src/modules/rust.rs
index 401f6e4ce..26ee377c9 100644
--- a/src/modules/rust.rs
+++ b/src/modules/rust.rs
@@ -23,7 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
Some(rust_version) => {
const RUST_CHAR: &str = "๐Ÿฆ€ ";
- let mut module = context.new_module("rust")?;
+ let mut module = context.new_module("rust");
let module_style = module
.config_value_style("style")
.unwrap_or_else(|| Color::Red.bold());
diff --git a/src/modules/username.rs b/src/modules/username.rs
index 07ecc5b14..c27896987 100644
--- a/src/modules/username.rs
+++ b/src/modules/username.rs
@@ -18,7 +18,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
const ROOT_UID: Option<u32> = Some(0);
let user_uid = get_uid();
if user != logname || ssh_connection.is_some() || user_uid == ROOT_UID {
- let mut module = context.new_module("username")?;
+ let mut module = context.new_module("username");
let module_style = get_mod_style(user_uid, &module);
module.set_style(module_style);
module.new_segment("username", &user?);
diff --git a/src/print.rs b/src/print.rs
index 1ea1648ff..2b730e259 100644
--- a/src/print.rs
+++ b/src/print.rs
@@ -81,6 +81,7 @@ pub fn prompt(args: ArgMatches) {
let modules = &prompt_order
.par_iter()
+ .filter(|module| context.is_module_enabled(module))
.map(|module| modules::handle(module, &context)) // Compute modules
.flatten()
.collect::<Vec<Module>>(); // Remove segments set to `None`
diff --git a/tests/testsuite/cmd_duration.rs b/tests/testsuite/cmd_duration.rs
index a82790327..287944cbd 100644
--- a/tests/testsuite/cmd_duration.rs
+++ b/tests/testsuite/cmd_duration.rs
@@ -58,20 +58,3 @@ fn config_5s_duration_10s() -> io::Result<()> {
assert_eq!(expected, actual);
Ok(())
}
-
-#[test]
-fn config_disabled() -> io::Result<()> {
- let output = common::render_module("cmd_duration")
- .use_config(toml::toml! {
- [cmd_duration]
- disabled = true
- min_time = 5
- })
- .arg("--cmd-duration=10")
- .output()?;
- let actual = String::from_utf8(output.stdout).unwrap();
-
- let expected = "";
- assert_eq!(expected, actual);
- Ok(())
-}
diff --git a/tests/testsuite/common.rs b/tests/testsuite/common.rs
index babe43a17..e06f5af43 100644
--- a/tests/testsuite/common.rs
+++ b/tests/testsuite/common.rs
@@ -1,15 +1,12 @@
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
use std::io::prelude::*;
use std::io::{Error, ErrorKind};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, fs, io, process};
-lazy_static! {
- static ref MANIFEST_DIR: &'static Path = Path::new(env!("CARGO_MANIFEST_DIR"));
- pub static ref FIXTURES_DIR: PathBuf = MANIFEST_DIR.join("tests/fixtures");
- static ref EMPTY_CONFIG: PathBuf = MANIFEST_DIR.join("empty_config.toml");
-}
+static MANIFEST_DIR: Lazy<&'static Path> = Lazy::new(|| Path::new(env!("CARGO_MANIFEST_DIR")));
+static EMPTY_CONFIG: Lazy<PathBuf> = Lazy::new(|| MANIFEST_DIR.join("empty_config.toml"));
/// Render the full starship prompt
pub fn render_prompt() -> process::Command {
diff --git a/tests/testsuite/configuration.rs b/tests/testsuite/configuration.rs
index a9daefb63..6d058be96 100644
--- a/tests/testsuite/configuration.rs
+++ b/tests/testsuite/configuration.rs
@@ -20,20 +20,6 @@ fn char_symbol_configuration() -> io::Result<()> {
}
#[test]
-fn disabled_module() -> io::Result<()> {
- let output = common::render_module("package")
- .use_config(toml::toml! {
- [package]
- disabled = true
- })
- .output()?;
- let actual = String::from_utf8(output.stdout).unwrap();
- assert_eq!("", actual);
-
- Ok(())
-}
-
-#[test]
fn add_newline_configuration() -> io::Result<()> {
// Start prompt with newline
let default_output = common::render_prompt().output()?;
diff --git a/tests/testsuite/git_branch.rs b/tests/testsuite/git_branch.rs
index ab1cc3c96..095615f80 100644
--- a/tests/testsuite/git_branch.rs
+++ b/tests/testsuite/git_branch.rs
@@ -1,6 +1,5 @@
use ansi_term::Color;
use git2::Repository;
-use std::env;
use std::io;
use std::process::Command;
diff --git a/tests/testsuite/git_status.rs b/tests/testsuite/git_status.rs
index e2be95c21..3a2626b1e 100644
--- a/tests/testsuite/git_status.rs
+++ b/tests/testsuite/git_status.rs
@@ -1,6 +1,5 @@
use ansi_term::Color;
use git2::Repository;
-use std::env;
use std::fs::{self, File};
use std::io;
use std::process::Command;
diff --git a/tests/testsuite/golang.rs b/tests/testsuite/golang.rs
index b5d37bc1f..a2c50e72c 100644
--- a/tests/testsuite/golang.rs
+++ b/tests/testsuite/golang.rs
@@ -2,7 +2,7 @@ use ansi_term::Color;
use std::fs::{self, File};
use std::io;
-use crate::common::{self, TestCommand};
+use crate::common;
#[test]
fn folder_without_go_files() -> io::Result<()> {
@@ -138,24 +138,3 @@ fn folder_with_gopkg_lock() -> io::Result<()> {
assert_eq!(expected, actual);
Ok(())
}
-
-#[test]
-#[ignore]
-fn config_disabled() -> io::Result<()> {
- let dir = common::new_tempdir()?;
- File::create(dir.path().join("main.go"))?;
-
- let output = common::render_module("golang")
- .use_conf