The Problem
I make quite heavy use of nix shell
and nix develop
and find that I often forget what shell “level of depth” I’m at in my terminal session.
I’d love for some solution where I could keep track of what depth I’m at in my shell invocations, and potentially the name
of the current shell if the shell is from a single shell derivation.
Judging by this issue and the requests for env vars or custom prompts, it appears I’m far from the only one.
https://github.com/NixOS/nix/issues/6677
Impure Solutions
It appears that some of the concerns with supporting environment variable solutions are w.r.t. shell reproducibility, which makes a lot of sense. This also implies custom prompts are a no-go, as they are normally indicated by an env var like PS1
.
That said, it seems like it could at least be useful to allow the user to opt-in to these likely innocuous impurities in their Nix configuration?
Maybe we could contain the impurities by allowing user config to specify something like a special “prompt derivation” that just specifies PS1
as an output and is supplied the shell’s derivation and current depth as an input?
Temporary Workarounds?
Either way, I’m curious what folks are doing as a workaround here in the meantime? Some kind of visual indicator that didn’t require input would be ideal.
In the meantime, I’m thinking I might just make a short-hand for:
echo "${PATH//:/$'\n'}"
which lists the current PATH
directories. This at least makes it obvious whether or not you’re in a nix shell as it lists all of the shell’s buildInputs
paths individually. It also gives an idea of which shell you’re in as you can see all the inputs individually.
That said, this isn’t ideal as it requires input to find where you are, and the output can be noisey or hard to parse depending on how complicated the shell is.
Any other suggestions/solutions appreciated!