From 33b1fdcd6ec1e94255e40affaf9841f7657a5c3d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 5 Jun 2026 19:04:13 +0200 Subject: [PATCH] show instance details in shell prompt fixes #20 --- src/php.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/php.rs b/src/php.rs index d1abaa2..3e542c0 100644 --- a/src/php.rs +++ b/src/php.rs @@ -1,4 +1,3 @@ -use owo_colors::OwoColorize; use crate::config::ProxyConfig; use crate::database::Database; use crate::image::{image_version, pull_image, ImageVersion}; @@ -12,7 +11,9 @@ use bollard::Docker; use itertools::Itertools; use maplit::hashmap; use miette::{IntoDiagnostic, Report, Result, WrapErr}; +use owo_colors::OwoColorize; use reqwest::{Client, Url}; +use std::iter::once; use std::net::{IpAddr, Ipv4Addr}; use std::str::FromStr; use std::time::Duration; @@ -129,7 +130,11 @@ impl PhpVersion { let haze_version = ImageVersion::from_str(env!("CARGO_PKG_VERSION")); if let (Some(image_version), Ok(haze_version)) = (image_version, haze_version) { if image_version < haze_version { - eprintln!("{}: image version is out of date, run {} to update.", "Warning".red(), "haze update".blue()); + eprintln!( + "{}: image version is out of date, run {} to update.", + "Warning".red(), + "haze update".blue() + ); eprintln!(" Haze version: {}", haze_version.bright_yellow()); eprintln!(" Image version: {}", image_version.bright_yellow()); } @@ -160,6 +165,20 @@ impl PhpVersion { proxy_config.addr(id, IpAddr::V4(Ipv4Addr::LOCALHOST)) )); + env.push(format!("INSTANCE_ID={}", id.trim_start_matches("haze-"))); + env.push(format!("INSTANCE_PHP={}", self.name())); + env.push(format!("INSTANCE_DB={}", db.family())); + env.push(format!( + "INSTANCE_SERVICES={}", + once("") + .chain(services.iter().map(ServiceTrait::name)) + .collect::>() + .join(" ") + )); + env.push( + "PS1=${INSTANCE_ID} [${INSTANCE_PHP} ${INSTANCE_DB}${INSTANCE_SERVICES}]> ".into(), + ); + env.push(format!("HOST_IP={host}")); if !proxy_config.address.is_empty() { env.push(format!("PROXY_BASE={}", proxy_config.address));