envdir icon indicating copy to clipboard operation
envdir copied to clipboard

new feature: optional prompt for envshell

Open slafs opened this issue 10 years ago • 18 comments

this sets a new env variable called ENVDIR_PS1 before running a new shell so for example in bash it can be used to set a new shell prompt (similar to virtualenv)

all you'd need to do is add a line similar to this at the bottom of your .bashrc

PS1=${ENVDIR_PS1:-${PS1}}

so after running envshell ./test/ you would get [envdir:test] at the beginning of your prompt.

slafs avatar Oct 15 '14 22:10 slafs

I like the idea (an indicator that an envshell is active) in general, but this approach requires PS1 to be exported.

Since I am using another method than PS1 anyway to setup my prompt, something like setting ENVDIR_PATH or/and ENVSHELL_NAME in general might make more sense.

FWIW, I am currently exporting ENVSHELL myself for my prompt.

blueyed avatar Oct 16 '14 01:10 blueyed

Yes. This PR was probably too bash-specific. So basically you give this idea a thumbs up ? I can change the PR but should we provide a whole path in ENVDIR_PATH or just a basename in ENVSHELL_NAME or both?

slafs avatar Oct 16 '14 10:10 slafs

How about now? This should be shell/prompt agnostic :). Now you can have something like

if [ -n "$ENVSHELL_NAME" ]; then PS1=[envshell:$ENVSHELL_NAME]$PS1; fi

at the end of your .bashrc.

slafs avatar Oct 17 '14 08:10 slafs

:+1:

blueyed avatar Oct 17 '14 20:10 blueyed

I've added some docs about those two new env variables.

slafs avatar Oct 24 '14 20:10 slafs

I feel like this could do with a test to ensure the vars are set. @slafs would you be prepared to do that? Then I'll try to get this merged in.

judy2k avatar Jun 09 '15 21:06 judy2k

Sure! Will try.

slafs avatar Jun 09 '15 21:06 slafs

@slafs Any update on this?

blueyed avatar Nov 20 '15 19:11 blueyed

Done :). Although we probably need #45 first.

slafs avatar Nov 21 '15 12:11 slafs

Thanks!

#45 is merged - please rebase on master.

blueyed avatar Nov 23 '15 22:11 blueyed

Done. Looks like appveyor failed on py26 (not on mine test though).

slafs avatar Mar 09 '16 11:03 slafs

I would say by now that only ENVSHELL_PATH is required, because ENVSHELL_NAME can easily get derived from it in your shell (${ENVSHELL_PATH##*/}).

blueyed avatar Mar 12 '16 17:03 blueyed

I wouldn't say "easily". That's some serious bash-fu right there. I can remove it, but I'd "vote" it to stay.

slafs avatar Mar 12 '16 17:03 slafs

I wouldn't say "easily".

I can see that it's not obvious, but should be known / easy to find if you're into shell scripting. What about $(basename "$ENVSHELL_PATH")?

We could also provide the code in the documentation.

What do others think?

blueyed avatar Mar 13 '16 13:03 blueyed

Oh, right. I forgot that basename is also present in bash. I'm ok with this then.

slafs avatar Mar 13 '16 20:03 slafs

Merrrgggeeeeeeeee :beers:

decentral1se avatar Mar 23 '16 22:03 decentral1se

@lwm ENVSHELL_NAME is still in the PR.

@slafs Do you want to remove it? Does everybody agree that a single env var is enough?

I'm really undecided on this myself.

blueyed avatar Mar 24 '16 00:03 blueyed

yes, I'll remove it.

slafs avatar May 12 '16 07:05 slafs