Closed Georacer closed 4 years ago
Found a possible solution, after a few hours of sed hacking:
# Find conda environment
function get_conda_env() {
conda_path="$(which conda)"
if [[ "$conda_path" != "" ]]; then
conda_env="$(conda info 2> /dev/null | sed -e '/^[[:blank:]]*active environment/!d' | sed -r 's/^[[:blank:]]+active environment : ([[:alnum:]]+).*$/\1/g')"
if [[ "$conda_env" == "None" ]]; then
echo ""
else
echo "($conda_env) "
fi
else
echo ""
fi
}
The only problem is that the base command conda info
takes a second to return, so each new shell is less snappy at startup.
Perhaps a more hacky but more performing way would be to capture the user's conda activate <env_name>
command and use that as info source? Would that be possible?
I think the plethora of tools like this makes supporting them prohibitive. Curious if Todd will have a different opinion though.
Oooh, this issue was introduced by our move to PROMPT_COMMAND
in 1.0.0
, which was necessary for exit code support
I've used a similar setup that extends PS1
with virtualenvwrapper
(currently assuming this) as well as a custom chruby
detection:
https://github.com/twolfson/dotfiles/blob/2017.1113.1132/.bashrc#L371-L372
Unsure if I have time to dig around on this tonight. Going to poke for maybe a few more minutes
If you don't hear from me, then assume I'll take a deeper look by Tuesday night
Alright, so it looks like virutalenvwrapper
/virtualenv
does PS1 extension as I expected:
workon
definition + activate
calls
PS1
extension in virtualenv
itself
Since that's such an established library, we really should figure out how to support PS1
shells =/ Maybe there's something with enabling exit code coloring via an opt-in, maybe something else
I do know that one solution would be user's extend their own PROMPT_COMMAND
but that seems backwards to me =/
Going to double check I didn't miss anything obvious like PS1=content$PS1
(feel like this would overbuild our PS1 every time)
Alllllright, got a real quick proof of concept working but the summarized solution is:
PROMPT_COMMAND
to only collect exit code and expose it to a global variablePS1
and read from global variable inside of a subshell commandI don't believe I have time to fully resolve this at the moment but for now I think it's fair to prioritize shell extension over exit code support
As a result, going to rollback 1.0.0
PROMPT_COMMAND
changes as patch version 1.0.1
. This also dovetails nicely in that the fix will look more like the 0.30.0
version than the 1.0.0
version
Alright, patched/reverted 1.0.1
has been released. I'll look into a proper reimplementation soon
No hard timeline since I don't want to rush it and ideally will have some local testing, I'm guessing tonight or next few days for a prototype and 1-2 weeks for PR + PR approval
Technically speaking, this issue is now resolved -- we're just missing exit code support once again, so closing the issue as resolved and reopening the exit code one
Okaayy... all of this went COMPLETELY over my head; I don't have the necessary background to digest this. But I'm happy that I triggered an interesting walkabout.
However, a bit irrelevant and just for the record, I found that the necessary information that I was looking for was in an environment variable called CONDA_PROMPT_MODIFIER
. I could have grabbed it from there.
Heh, as long as you understand that if you reinstall the latest version that no workaround is needed, then we're all good =)
And yes, it looks like CONDA_PROMPT_MODIFIER
is what you would have needed
Fwiw, PS1
is the default shell prompt that everyone sees and PROMPT_COMMAND
is commands that are run before every prompt is shown
Fwiw,
PS1
is the default shell prompt that everyone sees andPROMPT_COMMAND
is commands that are run before every prompt is shown
Aha, interesting... so conda uses the same mechanism as you (and I guess other people too) to modify the command prompt. The more you know...
As a heads up, exit code support has been added back in 1.1.0
with aforementioned PS1
patch. Let me know if it breaks your use case once again or not (pretty confident we're good now)
Works just dandy! Thanks!
In detail, the environment name works when I enable it. Any easy way to test the exit error support?
Any easy way to test the exit error support?
Using a command like false
should do the trick. Also using a keyboard interrupt on any running command (e.g. time cat
-> Ctrl+C)
Yes, the $ sign become red when erroring out withing a conda environment.
Hi there!
I really nice this utility, the new line before the command is a genius move!
Sadly I found a shortcoming. I'm regularly using conda to manage my development environment. When one types
conda activate <envname>
the environment is "activated" and its name is normally displayed before the prompt:(env_name) user@computer: <dir>$
The current configuration of sexy-bash-prompt doesn't allow for that. I get no indication of which environment I have activated.
Is there a way to add this?
Thanks!