Skip to content

Commit

Permalink
fix: fish prompt display looks wrong in tide (prefix-dev#1424)
Browse files Browse the repository at this point in the history
Fixes: prefix-dev#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 <[email protected]>
  • Loading branch information
tfriedel and tdejager authored May 22, 2024
1 parent 3a7c3ee commit 1e22646
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down

0 comments on commit 1e22646

Please sign in to comment.