mirror of
https://github.com/starship/starship.git
synced 2025-02-02 03:19:28 +01:00
Merge branch 'master' into conditional-style
This commit is contained in:
commit
6019d8b1ac
@ -43,7 +43,7 @@
|
||||
"plugins": [
|
||||
"https://github.com/dprint/dprint-plugin-typescript/releases/download/0.80.2/plugin.wasm",
|
||||
"https://github.com/dprint/dprint-plugin-json/releases/download/0.17.0/plugin.wasm",
|
||||
"https://github.com/dprint/dprint-plugin-markdown/releases/download/0.15.1/plugin.wasm",
|
||||
"https://github.com/dprint/dprint-plugin-markdown/releases/download/0.15.2/plugin.wasm",
|
||||
"https://github.com/dprint/dprint-plugin-toml/releases/download/0.5.4/plugin.wasm"
|
||||
]
|
||||
}
|
||||
|
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -283,9 +283,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.1.1"
|
||||
version = "4.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ec7a4128863c188deefe750ac1d1dfe66c236909f845af04beed823638dc1b2"
|
||||
checksum = "d8d93d855ce6a0aa87b8473ef9169482f40abaa2e9e0993024c35c902cbd5920"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
@ -300,9 +300,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.1.0"
|
||||
version = "4.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce8955d4e8cd4f28f9a01c93a050194c4d131e73ca02f6636bcddbed867014d7"
|
||||
checksum = "3d6540eedc41f8a5a76cf3d8d458057dcdf817be4158a55b5f861f7a5483de75"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
@ -2908,9 +2908,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "systemstat"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed5158fd55089515c923306476aaf3fa8ffc29a902561bf0017166a93218831c"
|
||||
checksum = "a24aec24a9312c83999a28e3ef9db7e2afd5c64bf47725b758cdc1cafd5b0bd2"
|
||||
dependencies = [
|
||||
"bytesize",
|
||||
"lazy_static",
|
||||
@ -3079,9 +3079,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.10"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
|
||||
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
@ -3381,9 +3381,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.3.0"
|
||||
version = "4.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b"
|
||||
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
|
||||
dependencies = [
|
||||
"either",
|
||||
"libc",
|
||||
|
10
Cargo.toml
10
Cargo.toml
@ -43,8 +43,8 @@ git-repository-faster = ["git-features/zlib-stock", "git-repository/fast-sha1"]
|
||||
|
||||
[dependencies]
|
||||
chrono = { version = "0.4.23", default-features = false, features = ["clock", "std", "wasmbind"] }
|
||||
clap = { version = "4.1.1", features = ["derive", "cargo", "unicode"] }
|
||||
clap_complete = "4.1.0"
|
||||
clap = { version = "4.1.3", features = ["derive", "cargo", "unicode"] }
|
||||
clap_complete = "4.1.1"
|
||||
dirs-next = "2.0.0"
|
||||
dunce = "1.0.3"
|
||||
gethostname = "0.4.1"
|
||||
@ -78,15 +78,15 @@ shadow-rs = { version = "0.20.0", default-features = false }
|
||||
# see: https://github.com/svartalf/rust-battery/issues/33
|
||||
starship-battery = { version = "0.7.9", optional = true }
|
||||
strsim = "0.10.0"
|
||||
systemstat = "=0.2.2"
|
||||
systemstat = "=0.2.3"
|
||||
terminal_size = "0.2.3"
|
||||
toml = { version = "0.5.10", features = ["preserve_order"] }
|
||||
toml = { version = "0.5.11", features = ["preserve_order"] }
|
||||
toml_edit = "0.17.1"
|
||||
unicode-segmentation = "1.10.0"
|
||||
unicode-width = "0.1.10"
|
||||
urlencoding = "2.1.2"
|
||||
versions = "4.1.0"
|
||||
which = "4.3.0"
|
||||
which = "4.4.0"
|
||||
yaml-rust = "0.4.5"
|
||||
|
||||
process_control = { version = "4.0.1", features = ["crossbeam-channel"] }
|
||||
|
@ -26,18 +26,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
return Some("OCI".into());
|
||||
}
|
||||
|
||||
// WSL with systemd will set the contents of this file to "wsl"
|
||||
// Avoid showing the container module in that case
|
||||
let systemd_path = context_path(context, "/run/systemd/container");
|
||||
if utils::read_file(systemd_path)
|
||||
.ok()
|
||||
.filter(|s| s.trim() != "wsl")
|
||||
.is_some()
|
||||
{
|
||||
// systemd
|
||||
return Some("Systemd".into());
|
||||
}
|
||||
|
||||
let container_env_path = context_path(context, "/run/.containerenv");
|
||||
|
||||
if container_env_path.exists() {
|
||||
@ -60,6 +48,18 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
return Some(image_res);
|
||||
}
|
||||
|
||||
// WSL with systemd will set the contents of this file to "wsl"
|
||||
// Avoid showing the container module in that case
|
||||
// Honor the contents of this file if "docker" and not running in podman or wsl
|
||||
let systemd_path = context_path(context, "/run/systemd/container");
|
||||
if let Ok(s) = utils::read_file(systemd_path) {
|
||||
match s.trim() {
|
||||
"docker" => return Some("Docker".into()),
|
||||
"wsl" => (),
|
||||
_ => return Some("Systemd".into()),
|
||||
}
|
||||
}
|
||||
|
||||
if context_path(context, "/.dockerenv").exists() {
|
||||
// docker
|
||||
return Some("Docker".into());
|
||||
@ -137,6 +137,12 @@ mod tests {
|
||||
|
||||
let root_path = renderer.root_path();
|
||||
|
||||
// simulate file found on ubuntu images to ensure podman containerenv is preferred
|
||||
let systemd_path = root_path.join("run/systemd/container");
|
||||
|
||||
fs::create_dir_all(systemd_path.parent().unwrap())?;
|
||||
utils::write_file(&systemd_path, "docker\n")?;
|
||||
|
||||
let containerenv = root_path.join("run/.containerenv");
|
||||
|
||||
fs::create_dir_all(containerenv.parent().unwrap())?;
|
||||
@ -185,9 +191,12 @@ mod tests {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
#[test]
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_containerenv_systemd() -> std::io::Result<()> {
|
||||
fn containerenv_systemd(
|
||||
name: Option<&str>,
|
||||
display: Option<&str>,
|
||||
) -> std::io::Result<(Option<String>, Option<String>)> {
|
||||
let renderer = ModuleRenderer::new("container")
|
||||
// For a custom config
|
||||
.config(toml::toml! {
|
||||
@ -200,7 +209,12 @@ mod tests {
|
||||
let systemd_path = root_path.join("run/systemd/container");
|
||||
|
||||
fs::create_dir_all(systemd_path.parent().unwrap())?;
|
||||
utils::write_file(&systemd_path, "systemd-nspawn\n")?;
|
||||
|
||||
let contents = match name {
|
||||
Some(name) => format!("{name}\n"),
|
||||
None => "systemd-nspawn\n".to_string(),
|
||||
};
|
||||
utils::write_file(&systemd_path, contents)?;
|
||||
|
||||
// The output of the module
|
||||
let actual = renderer
|
||||
@ -208,13 +222,23 @@ mod tests {
|
||||
.collect();
|
||||
|
||||
// The value that should be rendered by the module.
|
||||
let expected = Some(format!(
|
||||
"{} ",
|
||||
Color::Red
|
||||
.bold()
|
||||
.dimmed()
|
||||
.paint(format!("⬢ [{}]", "Systemd"))
|
||||
));
|
||||
let expected = display.map(|_| {
|
||||
format!(
|
||||
"{} ",
|
||||
Color::Red
|
||||
.bold()
|
||||
.dimmed()
|
||||
.paint(format!("⬢ [{}]", display.unwrap_or("Systemd")))
|
||||
)
|
||||
});
|
||||
|
||||
Ok((actual, expected))
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_containerenv_systemd() -> std::io::Result<()> {
|
||||
let (actual, expected) = containerenv_systemd(None, Some("Systemd"))?;
|
||||
|
||||
// Assert that the actual and expected values are the same
|
||||
assert_eq!(actual, expected);
|
||||
@ -224,28 +248,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_containerenv_wsl() -> std::io::Result<()> {
|
||||
let renderer = ModuleRenderer::new("container")
|
||||
// For a custom config
|
||||
.config(toml::toml! {
|
||||
[container]
|
||||
disabled = false
|
||||
});
|
||||
fn test_containerenv_docker_in_systemd() -> std::io::Result<()> {
|
||||
let (actual, expected) = containerenv_systemd(Some("docker"), Some("Docker"))?;
|
||||
|
||||
let root_path = renderer.root_path();
|
||||
// Assert that the actual and expected values are the same
|
||||
assert_eq!(actual, expected);
|
||||
|
||||
let systemd_path = root_path.join("run/systemd/container");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fs::create_dir_all(systemd_path.parent().unwrap())?;
|
||||
utils::write_file(&systemd_path, "wsl\n")?;
|
||||
|
||||
// The output of the module
|
||||
let actual = renderer
|
||||
// Run the module and collect the output
|
||||
.collect();
|
||||
|
||||
// The value that should be rendered by the module.
|
||||
let expected = None;
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_containerenv_wsl_in_systemd() -> std::io::Result<()> {
|
||||
let (actual, expected) = containerenv_systemd(Some("wsl"), None)?;
|
||||
|
||||
// Assert that the actual and expected values are the same
|
||||
assert_eq!(actual, expected);
|
||||
|
Loading…
Reference in New Issue
Block a user