From 1e22646cc70b329c87de5b449c4abab1ef8b8b30 Mon Sep 17 00:00:00 2001 From: Thomas Friedel Date: Wed, 22 May 2024 10:23:27 +0200 Subject: [PATCH] fix: fish prompt display looks wrong in tide (#1424) Fixes: https://github.com/prefix-dev/pixi/issues/1407 Adapted the prompt logic from conda and made some small changes for pixi fish shell. The environment name is displayed on the right side per default, but can be moved to the left like this: `set -gx CONDA_LEFT_PROMPT 1` --------- Co-authored-by: Tim de Jager --- src/prompt.rs | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/prompt.rs b/src/prompt.rs index 9d037e6fc..0280edaf9 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -19,10 +19,44 @@ pub fn get_zsh_hook(env_name: &str) -> String { /// Set default pixi prompt for the fish shell pub fn get_fish_prompt(env_name: &str) -> String { format!( - "functions -c fish_prompt old_fish_prompt; \ - function fish_prompt; \ - echo \"({})\" (old_fish_prompt); \ - end;", + r#" + function __pixi_add_prompt + set_color -o green + echo -n "({}) " + set_color normal + end + + if not functions -q __fish_prompt_orig + functions -c fish_prompt __fish_prompt_orig + end + + if functions -q fish_right_prompt + if not functions -q __fish_right_prompt_orig + functions -c fish_right_prompt __fish_right_prompt_orig + end + else + function __fish_right_prompt_orig + # Placeholder function for when fish_right_prompt does not exist + echo "" + end + end + + function fish_prompt + set -l last_status $status + if set -q PIXI_LEFT_PROMPT + __pixi_add_prompt + end + __fish_prompt_orig + return $last_status + end + + function fish_right_prompt + if not set -q PIXI_LEFT_PROMPT + __pixi_add_prompt + end + __fish_right_prompt_orig + end + "#, env_name ) }