Kai Walter
Kai Walter

Reputation: 4041

How can I add a simple indicator in my Nix configuration so that I see, that I am in a nix shell or nix develop environment?

I want to have a simple indicator showing in my (zsh / oh-my-zsh) shell, that I am one level into a nix shell or nix develop environment / sub shell without modifying all my flake.nix or shell.nix:

user@hostname ~ nix shell nixpkgs#git
...
#2 user@hostname ~

Upvotes: 0

Views: 34

Answers (1)

Kai Walter
Kai Walter

Reputation: 4041

In my Nix Home Manager configuration I added some custom script lines which enhance the generated .zshrc to add the script level:

      programs.zsh = {
        enable = true;
...
        initExtra =
          ''
            if [[ $SHLVL -gt 1 ]]; then
              PROMPT="#''${SHLVL}''${PROMPT}"
            fi
          ''
      };

or with a simple Unicode symbol:

      programs.zsh = {
        enable = true;
...
        initExtra =
          ''
            if [[ $SHLVL -gt 1 ]]; then
              case $SHLVL in
                  2) PROMPT="⁚''${PROMPT}" ;;
                  3) PROMPT="⁖''${PROMPT}" ;;
                  4) PROMPT="⁘''${PROMPT}" ;;
                  *) PROMPT="⁙''${SHLVL}''${PROMPT}" ;;
              esac            
            fi

          ''
      };

Upvotes: 0

Related Questions