How do I modify my conda env variable in my terminal prompt?Modify prompt based on valueassigning a multiline...

Does the average primeness of natural numbers tend to zero?

How many letters suffice to construct words with no repetition?

LWC and complex parameters

How to answer pointed "are you quitting" questioning when I don't want them to suspect

What's the difference between repeating elections every few years and repeating a referendum after a few years?

Re-submission of rejected manuscript without informing co-authors

Finding files for which a command fails

What is the offset in a seaplane's hull?

Prime joint compound before latex paint?

Why airport relocation isn't done gradually?

What is GPS' 19 year rollover and does it present a cybersecurity issue?

Denied boarding due to overcrowding, Sparpreis ticket. What are my rights?

Where else does the Shulchan Aruch quote an authority by name?

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

I see my dog run

Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?

Need help identifying/translating a plaque in Tangier, Morocco

Hosting Wordpress in a EC2 Load Balanced Instance

Patience, young "Padovan"

"listening to me about as much as you're listening to this pole here"

Could Giant Ground Sloths have been a good pack animal for the ancient Mayans?

Can a planet have a different gravitational pull depending on its location in orbit around its sun?

extract characters between two commas?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?



How do I modify my conda env variable in my terminal prompt?


Modify prompt based on valueassigning a multiline variable (tcsh prompt) to anotherMac OS X: Terminal Prompt UsernameHow can avoid these spurious characters in my bash prompt?How does Git change the shell prompt in Aptana Studio's Cygwin Terminal?Terminal prompt is being written over top ofTerminal prompt overwrites current linePrompt customization problem with if clauseHow to configure zsh prompt so that its length is proportional to terminal widthHow can I properly use an American flag emoji in my bash prompt?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







3















I would like to customize my terminal prompt. Normally when a conda environment is activated the name of the environment is prepended to the PS1 string. I would like to customize this a bit more but have not been able to figure it out.



If I add changeps1: false to my .condarc file the terminal prompt is not modified when I activate a new environment. I can then modify the environment variable in my .bash_profile for example:



PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";



This returns the name of the environment colored how I would like surrounded by carrots, however this only works after I run source .bash_profile activating the environment has no effect, which is not unexpected.



My question is how to I update the prompt when activating the environment, or is there a better way of go about this?



This is related to this question



And this example profile However those do not directly address the issue that I am running into of the prompt not changing when activating environments










share|improve this question































    3















    I would like to customize my terminal prompt. Normally when a conda environment is activated the name of the environment is prepended to the PS1 string. I would like to customize this a bit more but have not been able to figure it out.



    If I add changeps1: false to my .condarc file the terminal prompt is not modified when I activate a new environment. I can then modify the environment variable in my .bash_profile for example:



    PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";



    This returns the name of the environment colored how I would like surrounded by carrots, however this only works after I run source .bash_profile activating the environment has no effect, which is not unexpected.



    My question is how to I update the prompt when activating the environment, or is there a better way of go about this?



    This is related to this question



    And this example profile However those do not directly address the issue that I am running into of the prompt not changing when activating environments










    share|improve this question



























      3












      3








      3


      1






      I would like to customize my terminal prompt. Normally when a conda environment is activated the name of the environment is prepended to the PS1 string. I would like to customize this a bit more but have not been able to figure it out.



      If I add changeps1: false to my .condarc file the terminal prompt is not modified when I activate a new environment. I can then modify the environment variable in my .bash_profile for example:



      PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";



      This returns the name of the environment colored how I would like surrounded by carrots, however this only works after I run source .bash_profile activating the environment has no effect, which is not unexpected.



      My question is how to I update the prompt when activating the environment, or is there a better way of go about this?



      This is related to this question



      And this example profile However those do not directly address the issue that I am running into of the prompt not changing when activating environments










      share|improve this question
















      I would like to customize my terminal prompt. Normally when a conda environment is activated the name of the environment is prepended to the PS1 string. I would like to customize this a bit more but have not been able to figure it out.



      If I add changeps1: false to my .condarc file the terminal prompt is not modified when I activate a new environment. I can then modify the environment variable in my .bash_profile for example:



      PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";



      This returns the name of the environment colored how I would like surrounded by carrots, however this only works after I run source .bash_profile activating the environment has no effect, which is not unexpected.



      My question is how to I update the prompt when activating the environment, or is there a better way of go about this?



      This is related to this question



      And this example profile However those do not directly address the issue that I am running into of the prompt not changing when activating environments







      terminal python prompt






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      0xSheepdog

      1,69311024




      1,69311024










      asked Oct 2 '18 at 23:15









      johnchasejohnchase

      687




      687






















          1 Answer
          1






          active

          oldest

          votes


















          2





          +50









          The problem here is that you're using double quotes and using a direct command substitution, which means the value of $(basename $CONDA_DEFAULT_ENV) (and therefore $CONDA_DEFAULT_ENV) will only be evaluated once, when that line of code is executed, and will be incorporated into PS1 as a verbatim string.



          The way bash processes PS1, it will evaluate $(...) sequences every time the prompt is printed, so what you need to do is preserve the sequence in its literal form (by escaping the $s with backslashes, for example), which should yield the result you're looking for.



          So this should work:



          PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";


          Or, better, add double quotes around the variable, so that the basename command will keep working if $CONDA_DEFAULT_ENV has spaces, or if it's empty or unset:



          PS1+="[${cyan}]<$(basename "$CONDA_DEFAULT_ENV)"> ";


          Note that I didn't escape ${cyan}, since it's OK to evaluate that only once, as it's not expected to change...



          Escaping metacharacters (such as $ and ") starts getting heavy at some point, so using single quotes to preserve the string verbatim is probably a better choice at some point, so we can do that. But since we want to still expand ${cyan}, let's mix double quotes and single quotes to achieve the desired result with minimal escaping:



          PS1+="[${cyan}]"'<$(basename "$CONDA_DEFAULT_ENV")> ';


          You might still have problems with setting the color to cyan without resetting it at the end... But that should be easy to fix, by adding another "[${...}]" block at the end with the code to reset formatting (not sure where your color constants are coming from, so check those for the reset code.) But it's possible that's not a problem in your specific environment, if you have further lines appending to PS1 to further modify it, that are also changing the color. (Which I imagine is your case, since you say what you have works whenever you source your profile.)






          share|improve this answer



















          • 1





            This works, and I also I appreciate the explanation of what was failing in my example. Thanks for a great answer!

            – johnchase
            Oct 17 '18 at 15:07












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472878%2fhow-do-i-modify-my-conda-env-variable-in-my-terminal-prompt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2





          +50









          The problem here is that you're using double quotes and using a direct command substitution, which means the value of $(basename $CONDA_DEFAULT_ENV) (and therefore $CONDA_DEFAULT_ENV) will only be evaluated once, when that line of code is executed, and will be incorporated into PS1 as a verbatim string.



          The way bash processes PS1, it will evaluate $(...) sequences every time the prompt is printed, so what you need to do is preserve the sequence in its literal form (by escaping the $s with backslashes, for example), which should yield the result you're looking for.



          So this should work:



          PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";


          Or, better, add double quotes around the variable, so that the basename command will keep working if $CONDA_DEFAULT_ENV has spaces, or if it's empty or unset:



          PS1+="[${cyan}]<$(basename "$CONDA_DEFAULT_ENV)"> ";


          Note that I didn't escape ${cyan}, since it's OK to evaluate that only once, as it's not expected to change...



          Escaping metacharacters (such as $ and ") starts getting heavy at some point, so using single quotes to preserve the string verbatim is probably a better choice at some point, so we can do that. But since we want to still expand ${cyan}, let's mix double quotes and single quotes to achieve the desired result with minimal escaping:



          PS1+="[${cyan}]"'<$(basename "$CONDA_DEFAULT_ENV")> ';


          You might still have problems with setting the color to cyan without resetting it at the end... But that should be easy to fix, by adding another "[${...}]" block at the end with the code to reset formatting (not sure where your color constants are coming from, so check those for the reset code.) But it's possible that's not a problem in your specific environment, if you have further lines appending to PS1 to further modify it, that are also changing the color. (Which I imagine is your case, since you say what you have works whenever you source your profile.)






          share|improve this answer



















          • 1





            This works, and I also I appreciate the explanation of what was failing in my example. Thanks for a great answer!

            – johnchase
            Oct 17 '18 at 15:07
















          2





          +50









          The problem here is that you're using double quotes and using a direct command substitution, which means the value of $(basename $CONDA_DEFAULT_ENV) (and therefore $CONDA_DEFAULT_ENV) will only be evaluated once, when that line of code is executed, and will be incorporated into PS1 as a verbatim string.



          The way bash processes PS1, it will evaluate $(...) sequences every time the prompt is printed, so what you need to do is preserve the sequence in its literal form (by escaping the $s with backslashes, for example), which should yield the result you're looking for.



          So this should work:



          PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";


          Or, better, add double quotes around the variable, so that the basename command will keep working if $CONDA_DEFAULT_ENV has spaces, or if it's empty or unset:



          PS1+="[${cyan}]<$(basename "$CONDA_DEFAULT_ENV)"> ";


          Note that I didn't escape ${cyan}, since it's OK to evaluate that only once, as it's not expected to change...



          Escaping metacharacters (such as $ and ") starts getting heavy at some point, so using single quotes to preserve the string verbatim is probably a better choice at some point, so we can do that. But since we want to still expand ${cyan}, let's mix double quotes and single quotes to achieve the desired result with minimal escaping:



          PS1+="[${cyan}]"'<$(basename "$CONDA_DEFAULT_ENV")> ';


          You might still have problems with setting the color to cyan without resetting it at the end... But that should be easy to fix, by adding another "[${...}]" block at the end with the code to reset formatting (not sure where your color constants are coming from, so check those for the reset code.) But it's possible that's not a problem in your specific environment, if you have further lines appending to PS1 to further modify it, that are also changing the color. (Which I imagine is your case, since you say what you have works whenever you source your profile.)






          share|improve this answer



















          • 1





            This works, and I also I appreciate the explanation of what was failing in my example. Thanks for a great answer!

            – johnchase
            Oct 17 '18 at 15:07














          2





          +50







          2





          +50



          2




          +50





          The problem here is that you're using double quotes and using a direct command substitution, which means the value of $(basename $CONDA_DEFAULT_ENV) (and therefore $CONDA_DEFAULT_ENV) will only be evaluated once, when that line of code is executed, and will be incorporated into PS1 as a verbatim string.



          The way bash processes PS1, it will evaluate $(...) sequences every time the prompt is printed, so what you need to do is preserve the sequence in its literal form (by escaping the $s with backslashes, for example), which should yield the result you're looking for.



          So this should work:



          PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";


          Or, better, add double quotes around the variable, so that the basename command will keep working if $CONDA_DEFAULT_ENV has spaces, or if it's empty or unset:



          PS1+="[${cyan}]<$(basename "$CONDA_DEFAULT_ENV)"> ";


          Note that I didn't escape ${cyan}, since it's OK to evaluate that only once, as it's not expected to change...



          Escaping metacharacters (such as $ and ") starts getting heavy at some point, so using single quotes to preserve the string verbatim is probably a better choice at some point, so we can do that. But since we want to still expand ${cyan}, let's mix double quotes and single quotes to achieve the desired result with minimal escaping:



          PS1+="[${cyan}]"'<$(basename "$CONDA_DEFAULT_ENV")> ';


          You might still have problems with setting the color to cyan without resetting it at the end... But that should be easy to fix, by adding another "[${...}]" block at the end with the code to reset formatting (not sure where your color constants are coming from, so check those for the reset code.) But it's possible that's not a problem in your specific environment, if you have further lines appending to PS1 to further modify it, that are also changing the color. (Which I imagine is your case, since you say what you have works whenever you source your profile.)






          share|improve this answer













          The problem here is that you're using double quotes and using a direct command substitution, which means the value of $(basename $CONDA_DEFAULT_ENV) (and therefore $CONDA_DEFAULT_ENV) will only be evaluated once, when that line of code is executed, and will be incorporated into PS1 as a verbatim string.



          The way bash processes PS1, it will evaluate $(...) sequences every time the prompt is printed, so what you need to do is preserve the sequence in its literal form (by escaping the $s with backslashes, for example), which should yield the result you're looking for.



          So this should work:



          PS1+="[${cyan}]<$(basename $CONDA_DEFAULT_ENV)> ";


          Or, better, add double quotes around the variable, so that the basename command will keep working if $CONDA_DEFAULT_ENV has spaces, or if it's empty or unset:



          PS1+="[${cyan}]<$(basename "$CONDA_DEFAULT_ENV)"> ";


          Note that I didn't escape ${cyan}, since it's OK to evaluate that only once, as it's not expected to change...



          Escaping metacharacters (such as $ and ") starts getting heavy at some point, so using single quotes to preserve the string verbatim is probably a better choice at some point, so we can do that. But since we want to still expand ${cyan}, let's mix double quotes and single quotes to achieve the desired result with minimal escaping:



          PS1+="[${cyan}]"'<$(basename "$CONDA_DEFAULT_ENV")> ';


          You might still have problems with setting the color to cyan without resetting it at the end... But that should be easy to fix, by adding another "[${...}]" block at the end with the code to reset formatting (not sure where your color constants are coming from, so check those for the reset code.) But it's possible that's not a problem in your specific environment, if you have further lines appending to PS1 to further modify it, that are also changing the color. (Which I imagine is your case, since you say what you have works whenever you source your profile.)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Oct 17 '18 at 3:18









          filbrandenfilbranden

          10.7k21847




          10.7k21847








          • 1





            This works, and I also I appreciate the explanation of what was failing in my example. Thanks for a great answer!

            – johnchase
            Oct 17 '18 at 15:07














          • 1





            This works, and I also I appreciate the explanation of what was failing in my example. Thanks for a great answer!

            – johnchase
            Oct 17 '18 at 15:07








          1




          1





          This works, and I also I appreciate the explanation of what was failing in my example. Thanks for a great answer!

          – johnchase
          Oct 17 '18 at 15:07





          This works, and I also I appreciate the explanation of what was failing in my example. Thanks for a great answer!

          – johnchase
          Oct 17 '18 at 15:07


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472878%2fhow-do-i-modify-my-conda-env-variable-in-my-terminal-prompt%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...