devenv icon indicating copy to clipboard operation
devenv copied to clipboard

Starship is initialized wrong when loaded by direnv in zsh

Open hansalves opened this issue 2 years ago • 3 comments

Describe the bug Starship outputs wrong control characters when initialized from zsh through direnv. A clear and concise description of what the bug is.

To reproduce This can be reproduced by creating a .envrc (by running devenv init) in the starship example in git from zsh.

image

The integration adds eval "$(starship init $(echo $0))" to the enterShell. $0 will be the bash that's started by devenv, not the parent shell. This causes starship to output bash control characters instead of zsh ones.

Version

devenv: 0.6.3

hansalves avatar Nov 02 '23 16:11 hansalves

A workaround is to set the STARSHIP_SHELL variable to zsh. However, this will cause starships shell module to display zsh instead of bash.

hansalves avatar Jan 03 '24 12:01 hansalves

how did youll resolve this? I also have the same problem but the setting of STARSHIP_SHELL did not work

{ pkgs, lib, config, inputs, ... }:

{
  env.STARSHIP_SHELL = "zsh";

  enterShell = ''
    if [ -d ".venv" ]; then
      source .venv/bin/activate
    else
      uv venv && source .venv/bin/activate
    fi
  '';


  languages = {
    python = {
      enable = true;
      version = "3.11.6";
    };
  };


  dotenv.enable = true;

  starship.enable = true;
}

for context, I already use starship on my laptop. When I cd into the project directory, the shell shows the mangle of chars as in the screenshot above. But when I devenv shell its normal again.

cyberjar09 avatar May 29 '24 10:05 cyberjar09

I ended up not using starship from devenv, but initializing it from my .bashrc / .zshrc In devenv I now only have

    enterShell = ''
        export STARSHIP_CONFIG=${config.env.DEVENV_ROOT}/starship.toml
    .......
    ''

hansalves avatar May 29 '24 11:05 hansalves

This affects me with Fish as well:

image

therealpxc avatar Aug 09 '24 17:08 therealpxc

I've also noticed that the prompt gets mangled if I just call bash in there, but not if I invoke the systemwide bash provided by Nix. I think we've ended up with pkgs.bash rather than pkgs.bashInteractive. When I add pkgs.bashInteractive to my packages declaration in devenv.nix, my prompt looks fine when I enter a new shell with bash.

I think we can maybe fix this if we get mkShell or something similar to use bashInteractive instead of plain bash. The WIP devShellTools.buildShell might solve this issue.

therealpxc avatar Aug 09 '24 18:08 therealpxc