rsgalloway / envstack

Stacked environment variable management system.
Other
3 stars 0 forks source link

custom prompt strings #10

Open rsgalloway opened 6 days ago

rsgalloway commented 6 days ago

customize the prompt string $PS1 / %PROMPT% to display the current stack or environment.

something like this could be added to the stack file:

linux:
  <<: *default
  PS1: "[${ENV}] ${PS1}"

windows:
  <<: *default
  PROMPT: "[${ENV}] ${PROMPT}"

but I think what we want is the stack name:

(.venv) user@hostname:/current/directory$ envstack-init
[stack] (.venv) user@hostname:/current/directory$ envstack-init dev
[dev] (.venv) user@hostname:/current/directory$ 
rsgalloway commented 4 days ago

in addition, it looks like there is a "bug", or oversight, in the export and clear functions where it's unsetting env vars that are defined in the stack file, even if they existed in the old environment, e.g. PATH and PYTHONPATH:

$ envstack --export
...
export PATH="${BIN}:blah"
export PYTHONPATH="${LIB}:blah"

Then PATH and PYTHONPATH get unset unintentionally:

$ envstack --clear
...
unset PATH
unset PYTHONPATH

when they should really be restored to the old values:

$ envstack --clear
...
set PATH=${_OLD_PATH}
set PYTHONPATH=${_OLD_PYTHONPATH}
rsgalloway commented 2 days ago

work in progress in branch issue10/prompt_strings

rsgalloway commented 23 hours ago

there is also a bug in envstack.init() that is clearing env vars like PATH and PYTHONPATH if they are defined in the stack .env file, which means if they are referenced like this PATH: ${BIN}:%{PATH} then the values are cleared before they can be resolved

    # clear vars from stack namespace
    env = load_environ(name, environ=None)
    for key in env.keys():
        if key in os.environ:
            del os.environ[key]

    # store the name of the environment stack (e.g. for $PS1)
    os.environ["ENVSTACK"] = name

    # load the new environment
    env = load_environ(name)