-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1168/1285] (TENTATIVE) Implement changes to prompt behavior of activate.xsh #1299
Comments
Ping @scopatz, per @gaborbernat suggestion. |
The regex used above attempts to cover a number of likely and unlikely cases for usage of
In manual testing, this pattern successfully matches all of the following (and yes, some of these seem rather irrational to me, but I'm trying to cover the bases):
|
Hi there @bskinn - we can certainly change the behavior of xonsh (and cut a release) as needed. There is no reason that the Implementing I think that you understand this area a lot better than I do, so if you would like to alter xonsh here, I encourage a PR - which I'll get to promptly. If you need pointers on where to modify xonsh, just let me know! |
Heyo! Pleasure to e-meet you. 😀 Some scattershot brainstorming thoughts: Mmmm, the possibility of tweaking the xonsh machinery never occurred to me... there are a lot of different ways to slice this, and we should probably spend a fair amount of time hammering out the best approach (greatest flexibility for the user, most robust against implementation changes in xonsh/virtualenv, most backward-compatible, etc.). I'm somewhat hesitant to base new virtualenv prompt functionality on something that can only be relied upon in current+future xonsh versions; but, OTOH, the regex-swapping approach I've outlined above is potentially fragile to future evolution of xonsh. This is one reason why tests will be added to any & all stuff that happens here! I do like the idea of introducing I'm not sure how SUMMARY: From the perspectives of project codebase isolation, xonsh backward compatibility, and avoiding changes to the xonsh codebase if at all possible, I think I still favor the above regex swapout approach. It leaves the control of the prompt customization in the hands of the xonsh user, while still enabling this specific set of virtualenv-idiosyncratic behaviors. My big question is whether all of this is likely to hold true, especially the emphasized part:
Totally separately, implementing the |
One details question, @scopatz : is there a good way for inspecting the prompt string as actually rendered for the user, not just the |
I'd be quite interested in your thoughts as well on how best to approach this xonsh/virtualenv interop, @asottile. |
Nice to e-meet you too @bskinn!
Yes, There are a couple of different ways of doing this. If you are in Pure Python you can do: import builtins
# option 1: property
builtins.__xonsh__.shell.prompt
# option 2: function
builtins.__xonsh__.shell.prompt_formatter(builtins.__xonsh__.env['PROMPT']) Of course, in xonsh itself, these could just be: # option 1: property
__xonsh__.shell.prompt
# option 2: function
__xonsh__.shell.prompt_formatter($PROMPT) You can also render specific fields in the prompt using the
Agreed, I'll try to implement that now. |
pre/post implemented in xonsh/xonsh#2996 |
Since xonsh and virtualenv are already coupled via What about something like this (code drawn from your pre/post PR; docstring would need updating):
(If we could rely on 3.8, this would be a great place to use the new assignment expressions!!) |
Something like this would be nice! |
Ok, once that pre/post PR is merged, I can fork and implement, if you like? |
That's be awesome. @gforsyth will probably merge it soon. |
Ok @bskinn - that PR has been merged. Feel free to put in another! |
Per discussion at #1168 and #1285, as part of harmonizing the prompt handling behavior of the various supported shells, changes to
activate.xsh
may be warranted.xonsh
has its own machinery for reporting the current virtual environment in the prompt (the{env_name}
field), which is included in the default$PROMPT
of the shell. Of note, as currently implemented (v0.8.8)xonsh
always surrounds$VIRTUAL_ENV
with parentheses when one uses the built-in{env_name}
prompt-variable. Due to this machinery and its default configuration, implementation of--prompt
andVIRTUAL_ENV_DISABLE_PROMPT
behaviors require a rather different approach withxonsh
than with the other shells.By default,
xonsh
:__VIRTUAL_PROMPT__
prefix of "($VIRTUAL_ENV)
" (at least, if one uses the$PROMPT
that ships by default with the shell).($VIRTUAL_ENV)
".--prompt
.virtualenv env --prompt="(descriptive name) "
.VIRTUAL_ENV_DISABLE_PROMPT
.{env_name}
from their$PROMPT
if they don't want the venv name displayed. However, I can hypothesize situations where someone would want to have{env_name}
in$PROMPT
in general, but be able to suppress it in certain situations. Thus, I favor implementation.For the
VIRTUAL_ENV_DISABLE_PROMPT
behavior, the simplest approach seems to be removing the{env_name}
field (if present) from the current$PROMPT
:(Logic of the regex to be laid out in a following comment.)
For the behavior of the
--prompt
argument, the same regex should be useful. At this time, I envision two possible behaviors: (1) the custom prompt is inserted in place of any/all instances of{env_name}
, or (2) any/all instances of{env_name}
are removed from$PROMPT
, and the custom prompt is simply prepended to$PROMPT
. Currently, I favor (1).(1):
(2):
I think it's best NOT to use a raw-string enclosure for the
__VIRTUAL_PROMPT__
substitution marker, to allow users to have newlines &c. in their prompts if they want them?Care will have to be taken in either case to sanely handle situations where
__VIRTUAL_PROMPT__
contains double-quotes, if this hasn't been done already (haven't looked closely yet).The text was updated successfully, but these errors were encountered: