Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add reactivation to pixi shell #982

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const PROJECT_PREFIX: &str = "PIXI_PROJECT_";
impl Project {
/// Returns environment variables and their values that should be injected when running a command.
pub fn get_metadata_env(&self) -> HashMap<String, String> {
HashMap::from_iter([
let mut map = HashMap::from_iter([
(
format!("{PROJECT_PREFIX}ROOT"),
self.root().to_string_lossy().into_owned(),
Expand All @@ -40,7 +40,16 @@ impl Project {
version.to_string()
}),
),
])
]);

if let Ok(exe_path) = std::env::current_exe() {
map.insert(
"PIXI_EXE".to_string(),
exe_path.to_string_lossy().to_string(),
);
}

map
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ pub async fn execute(args: Args) -> miette::Result<()> {
match interactive_shell {
ShellEnum::NuShell(_) => prompt::get_nu_prompt(prompt_name.as_str()),
ShellEnum::PowerShell(_) => prompt::get_powershell_prompt(prompt_name.as_str()),
ShellEnum::Bash(_) => prompt::get_bash_prompt(prompt_name.as_str()),
ShellEnum::Zsh(_) => prompt::get_zsh_prompt(prompt_name.as_str()),
ShellEnum::Bash(_) => prompt::get_bash_hook(prompt_name.as_str()),
ShellEnum::Zsh(_) => prompt::get_zsh_hook(prompt_name.as_str()),
ShellEnum::Fish(_) => prompt::get_fish_prompt(prompt_name.as_str()),
ShellEnum::Xonsh(_) => prompt::get_xonsh_prompt(),
ShellEnum::CmdExe(_) => prompt::get_cmd_prompt(prompt_name.as_str()),
Expand Down
16 changes: 12 additions & 4 deletions src/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/// Set default pixi prompt for the bash shell
pub fn get_bash_prompt(env_name: &str) -> String {
format!("export PS1=\"({}) $PS1\"", env_name)
pub fn get_bash_hook(env_name: &str) -> String {
format!(
"export PS1=\"({}) $PS1\"\n{}",
env_name,
include_str!("shell_snippets/pixi-bash.sh")
)
}

/// Set default pixi prompt for the zsh shell
pub fn get_zsh_prompt(env_name: &str) -> String {
format!("export PS1=\"({}) $PS1\"", env_name)
pub fn get_zsh_hook(env_name: &str) -> String {
format!(
"export PS1=\"({}) $PS1\"\n{}",
env_name,
include_str!("shell_snippets/pixi-zsh.sh")
)
}

/// Set default pixi prompt for the fish shell
Expand Down
13 changes: 13 additions & 0 deletions src/shell_snippets/pixi-bash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pixi() {
local first_arg="$1"
local cmd="$PIXI_EXE $*"

eval "$cmd"

case "$first_arg" in
add|remove|install)
eval "$($PIXI_EXE shell-hook)"
hash -r
;;
esac
}
13 changes: 13 additions & 0 deletions src/shell_snippets/pixi-zsh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pixi() {
local first_arg="$1"
local cmd="$PIXI_EXE $*"

eval "$cmd"

case "$first_arg" in
add|remove|install)
eval "$($PIXI_EXE shell-hook)"
rehash # Clear the command hash table in zsh
;;
esac
}
Loading