From f480f4b32b12a4363a77df2b9c633854b953ac3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Wed, 17 Jan 2024 18:33:49 +0300 Subject: [PATCH] feat: add default environment to the shell-hook script --- src/cli/shell_hook.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cli/shell_hook.rs b/src/cli/shell_hook.rs index 6e6879753..45947e8c8 100644 --- a/src/cli/shell_hook.rs +++ b/src/cli/shell_hook.rs @@ -8,7 +8,7 @@ use rattler_shell::{ shell::ShellEnum, }; -use crate::prefix::Prefix; +use crate::{prefix::Prefix, Project}; /// Print the activation script #[derive(Parser, Debug)] @@ -20,13 +20,20 @@ pub struct Args { /// Generates the activation script. fn generate_activation_script(shell: Option) -> miette::Result { + let project = Project::discover()?; + let platform = Platform::current(); + let env_dir = project.default_environment().dir(); let prefix = Prefix::new(PathBuf::new())?; let shell = shell.unwrap_or_default(); - let platform = Platform::current(); let activator = Activator::from_path(prefix.root(), shell, platform).into_diagnostic()?; - let path = std::env::var("PATH") + let mut path = std::env::var("PATH") .ok() .map(|p| std::env::split_paths(&p).collect::>()); + if let Some(path) = path.as_mut() { + path.push(env_dir); + } else { + path = Some(vec![env_dir]); + } // If we are in a conda environment, we need to deactivate it before activating the host / build prefix let conda_prefix = std::env::var("CONDA_PREFIX").ok().map(|p| p.into());