Why don't git colours appear when using watch?












8















When running git status -sb I see:



enter image description here



I want to watch (from procps-ng 3.3.3) a repository. The --color option is supposed to keep colours.





Interestingly, it works with ls:



$ watch --color "ls --color"


Showing:



output from ls





However for git the colours disappear:



$ watch --color "git status -sb"


enter image description here





So, why does watch show colours from ls but not from git output?










share|improve this question

























  • Related: stackoverflow.com/questions/3793126/…

    – jobin
    Feb 20 '14 at 14:29











  • @Jobin, thanks, I actually commented at that link before posting this question :)

    – Drew Noakes
    Feb 20 '14 at 14:40
















8















When running git status -sb I see:



enter image description here



I want to watch (from procps-ng 3.3.3) a repository. The --color option is supposed to keep colours.





Interestingly, it works with ls:



$ watch --color "ls --color"


Showing:



output from ls





However for git the colours disappear:



$ watch --color "git status -sb"


enter image description here





So, why does watch show colours from ls but not from git output?










share|improve this question

























  • Related: stackoverflow.com/questions/3793126/…

    – jobin
    Feb 20 '14 at 14:29











  • @Jobin, thanks, I actually commented at that link before posting this question :)

    – Drew Noakes
    Feb 20 '14 at 14:40














8












8








8


2






When running git status -sb I see:



enter image description here



I want to watch (from procps-ng 3.3.3) a repository. The --color option is supposed to keep colours.





Interestingly, it works with ls:



$ watch --color "ls --color"


Showing:



output from ls





However for git the colours disappear:



$ watch --color "git status -sb"


enter image description here





So, why does watch show colours from ls but not from git output?










share|improve this question
















When running git status -sb I see:



enter image description here



I want to watch (from procps-ng 3.3.3) a repository. The --color option is supposed to keep colours.





Interestingly, it works with ls:



$ watch --color "ls --color"


Showing:



output from ls





However for git the colours disappear:



$ watch --color "git status -sb"


enter image description here





So, why does watch show colours from ls but not from git output?







git watch-command






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 20 '14 at 14:46









Braiam

52.4k20138223




52.4k20138223










asked Feb 20 '14 at 14:24









Drew NoakesDrew Noakes

2,81842847




2,81842847













  • Related: stackoverflow.com/questions/3793126/…

    – jobin
    Feb 20 '14 at 14:29











  • @Jobin, thanks, I actually commented at that link before posting this question :)

    – Drew Noakes
    Feb 20 '14 at 14:40



















  • Related: stackoverflow.com/questions/3793126/…

    – jobin
    Feb 20 '14 at 14:29











  • @Jobin, thanks, I actually commented at that link before posting this question :)

    – Drew Noakes
    Feb 20 '14 at 14:40

















Related: stackoverflow.com/questions/3793126/…

– jobin
Feb 20 '14 at 14:29





Related: stackoverflow.com/questions/3793126/…

– jobin
Feb 20 '14 at 14:29













@Jobin, thanks, I actually commented at that link before posting this question :)

– Drew Noakes
Feb 20 '14 at 14:40





@Jobin, thanks, I actually commented at that link before posting this question :)

– Drew Noakes
Feb 20 '14 at 14:40










3 Answers
3






active

oldest

votes


















4














The following statements are true:





  • watch runs the command in a new shell, sh.


  • .bashrc aliases ls as ls --color=auto to enable colours


  • sh doesn't inherit or use bash aliases.


So when watch runs ls, it's not asking for colours, it's just running the plain old version. You can circumvent this but —as aditya points out— you also need to enable colours on watch for it to process them properly.



A working example for ls is:



watch --colour -- ls --color=always


If you don't pass --color to watch, you'll see a bunch of ugly colour codes inline.





ls --color is interpreted as ls --colour=always.



ls --colour=auto does not print colour in watch. This suggests that it's inferring colour support from the terminal itself.



For more on the reason why, we can test if the watch shell thinks its a real terminal:



$ bash -c '[[ -t 1 ]] && echo "real terminal"'
real terminal

$ watch -- "bash -c '[[ -t 1 ]] && echo "real terminal"'"
# ... nothing.


I suspect that some applications are looking at that (or similar) to tell if they should turn on colours or not.






share|improve this answer





















  • 2





    But the OP wants to know why does this not work with git status -sb, even though it works with ls --color.

    – jobin
    Feb 20 '14 at 15:04











  • This makes sense. However there's no alias for git. The colouration is set within git's configuration directly. So this doesn't seem to be an aliasing issue.

    – Drew Noakes
    Feb 20 '14 at 15:06











  • Bingo. I'd set my colours to auto which, as you correctly surmised, was causing git to avoid the colour output. Using always instead has solved this problem. Many thanks!

    – Drew Noakes
    Feb 20 '14 at 15:10



















5














git uses a configuration value to determine whether to show coloured output or not.



For example:



git config --global color.ui auto


This sets the colour setting to auto globally. In auto mode, git will determine whether it's a real terminal before sending colour codes, as Oli suggested.



You can force this global value to always, however a better idea may be to apply it to a particular command:



git -c color.status=always status -sb


Putting it all together:



watch --color git -c color.status=always status -sb





share|improve this answer































    0














    It works if git (--color) and watch (-c) are told to use colors:



    watch -cd "git branch -va --color"





    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "89"
      };
      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: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      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%2faskubuntu.com%2fquestions%2f423672%2fwhy-dont-git-colours-appear-when-using-watch%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      The following statements are true:





      • watch runs the command in a new shell, sh.


      • .bashrc aliases ls as ls --color=auto to enable colours


      • sh doesn't inherit or use bash aliases.


      So when watch runs ls, it's not asking for colours, it's just running the plain old version. You can circumvent this but —as aditya points out— you also need to enable colours on watch for it to process them properly.



      A working example for ls is:



      watch --colour -- ls --color=always


      If you don't pass --color to watch, you'll see a bunch of ugly colour codes inline.





      ls --color is interpreted as ls --colour=always.



      ls --colour=auto does not print colour in watch. This suggests that it's inferring colour support from the terminal itself.



      For more on the reason why, we can test if the watch shell thinks its a real terminal:



      $ bash -c '[[ -t 1 ]] && echo "real terminal"'
      real terminal

      $ watch -- "bash -c '[[ -t 1 ]] && echo "real terminal"'"
      # ... nothing.


      I suspect that some applications are looking at that (or similar) to tell if they should turn on colours or not.






      share|improve this answer





















      • 2





        But the OP wants to know why does this not work with git status -sb, even though it works with ls --color.

        – jobin
        Feb 20 '14 at 15:04











      • This makes sense. However there's no alias for git. The colouration is set within git's configuration directly. So this doesn't seem to be an aliasing issue.

        – Drew Noakes
        Feb 20 '14 at 15:06











      • Bingo. I'd set my colours to auto which, as you correctly surmised, was causing git to avoid the colour output. Using always instead has solved this problem. Many thanks!

        – Drew Noakes
        Feb 20 '14 at 15:10
















      4














      The following statements are true:





      • watch runs the command in a new shell, sh.


      • .bashrc aliases ls as ls --color=auto to enable colours


      • sh doesn't inherit or use bash aliases.


      So when watch runs ls, it's not asking for colours, it's just running the plain old version. You can circumvent this but —as aditya points out— you also need to enable colours on watch for it to process them properly.



      A working example for ls is:



      watch --colour -- ls --color=always


      If you don't pass --color to watch, you'll see a bunch of ugly colour codes inline.





      ls --color is interpreted as ls --colour=always.



      ls --colour=auto does not print colour in watch. This suggests that it's inferring colour support from the terminal itself.



      For more on the reason why, we can test if the watch shell thinks its a real terminal:



      $ bash -c '[[ -t 1 ]] && echo "real terminal"'
      real terminal

      $ watch -- "bash -c '[[ -t 1 ]] && echo "real terminal"'"
      # ... nothing.


      I suspect that some applications are looking at that (or similar) to tell if they should turn on colours or not.






      share|improve this answer





















      • 2





        But the OP wants to know why does this not work with git status -sb, even though it works with ls --color.

        – jobin
        Feb 20 '14 at 15:04











      • This makes sense. However there's no alias for git. The colouration is set within git's configuration directly. So this doesn't seem to be an aliasing issue.

        – Drew Noakes
        Feb 20 '14 at 15:06











      • Bingo. I'd set my colours to auto which, as you correctly surmised, was causing git to avoid the colour output. Using always instead has solved this problem. Many thanks!

        – Drew Noakes
        Feb 20 '14 at 15:10














      4












      4








      4







      The following statements are true:





      • watch runs the command in a new shell, sh.


      • .bashrc aliases ls as ls --color=auto to enable colours


      • sh doesn't inherit or use bash aliases.


      So when watch runs ls, it's not asking for colours, it's just running the plain old version. You can circumvent this but —as aditya points out— you also need to enable colours on watch for it to process them properly.



      A working example for ls is:



      watch --colour -- ls --color=always


      If you don't pass --color to watch, you'll see a bunch of ugly colour codes inline.





      ls --color is interpreted as ls --colour=always.



      ls --colour=auto does not print colour in watch. This suggests that it's inferring colour support from the terminal itself.



      For more on the reason why, we can test if the watch shell thinks its a real terminal:



      $ bash -c '[[ -t 1 ]] && echo "real terminal"'
      real terminal

      $ watch -- "bash -c '[[ -t 1 ]] && echo "real terminal"'"
      # ... nothing.


      I suspect that some applications are looking at that (or similar) to tell if they should turn on colours or not.






      share|improve this answer















      The following statements are true:





      • watch runs the command in a new shell, sh.


      • .bashrc aliases ls as ls --color=auto to enable colours


      • sh doesn't inherit or use bash aliases.


      So when watch runs ls, it's not asking for colours, it's just running the plain old version. You can circumvent this but —as aditya points out— you also need to enable colours on watch for it to process them properly.



      A working example for ls is:



      watch --colour -- ls --color=always


      If you don't pass --color to watch, you'll see a bunch of ugly colour codes inline.





      ls --color is interpreted as ls --colour=always.



      ls --colour=auto does not print colour in watch. This suggests that it's inferring colour support from the terminal itself.



      For more on the reason why, we can test if the watch shell thinks its a real terminal:



      $ bash -c '[[ -t 1 ]] && echo "real terminal"'
      real terminal

      $ watch -- "bash -c '[[ -t 1 ]] && echo "real terminal"'"
      # ... nothing.


      I suspect that some applications are looking at that (or similar) to tell if they should turn on colours or not.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Apr 13 '17 at 12:37









      Community

      1




      1










      answered Feb 20 '14 at 14:59









      OliOli

      224k89567767




      224k89567767








      • 2





        But the OP wants to know why does this not work with git status -sb, even though it works with ls --color.

        – jobin
        Feb 20 '14 at 15:04











      • This makes sense. However there's no alias for git. The colouration is set within git's configuration directly. So this doesn't seem to be an aliasing issue.

        – Drew Noakes
        Feb 20 '14 at 15:06











      • Bingo. I'd set my colours to auto which, as you correctly surmised, was causing git to avoid the colour output. Using always instead has solved this problem. Many thanks!

        – Drew Noakes
        Feb 20 '14 at 15:10














      • 2





        But the OP wants to know why does this not work with git status -sb, even though it works with ls --color.

        – jobin
        Feb 20 '14 at 15:04











      • This makes sense. However there's no alias for git. The colouration is set within git's configuration directly. So this doesn't seem to be an aliasing issue.

        – Drew Noakes
        Feb 20 '14 at 15:06











      • Bingo. I'd set my colours to auto which, as you correctly surmised, was causing git to avoid the colour output. Using always instead has solved this problem. Many thanks!

        – Drew Noakes
        Feb 20 '14 at 15:10








      2




      2





      But the OP wants to know why does this not work with git status -sb, even though it works with ls --color.

      – jobin
      Feb 20 '14 at 15:04





      But the OP wants to know why does this not work with git status -sb, even though it works with ls --color.

      – jobin
      Feb 20 '14 at 15:04













      This makes sense. However there's no alias for git. The colouration is set within git's configuration directly. So this doesn't seem to be an aliasing issue.

      – Drew Noakes
      Feb 20 '14 at 15:06





      This makes sense. However there's no alias for git. The colouration is set within git's configuration directly. So this doesn't seem to be an aliasing issue.

      – Drew Noakes
      Feb 20 '14 at 15:06













      Bingo. I'd set my colours to auto which, as you correctly surmised, was causing git to avoid the colour output. Using always instead has solved this problem. Many thanks!

      – Drew Noakes
      Feb 20 '14 at 15:10





      Bingo. I'd set my colours to auto which, as you correctly surmised, was causing git to avoid the colour output. Using always instead has solved this problem. Many thanks!

      – Drew Noakes
      Feb 20 '14 at 15:10













      5














      git uses a configuration value to determine whether to show coloured output or not.



      For example:



      git config --global color.ui auto


      This sets the colour setting to auto globally. In auto mode, git will determine whether it's a real terminal before sending colour codes, as Oli suggested.



      You can force this global value to always, however a better idea may be to apply it to a particular command:



      git -c color.status=always status -sb


      Putting it all together:



      watch --color git -c color.status=always status -sb





      share|improve this answer




























        5














        git uses a configuration value to determine whether to show coloured output or not.



        For example:



        git config --global color.ui auto


        This sets the colour setting to auto globally. In auto mode, git will determine whether it's a real terminal before sending colour codes, as Oli suggested.



        You can force this global value to always, however a better idea may be to apply it to a particular command:



        git -c color.status=always status -sb


        Putting it all together:



        watch --color git -c color.status=always status -sb





        share|improve this answer


























          5












          5








          5







          git uses a configuration value to determine whether to show coloured output or not.



          For example:



          git config --global color.ui auto


          This sets the colour setting to auto globally. In auto mode, git will determine whether it's a real terminal before sending colour codes, as Oli suggested.



          You can force this global value to always, however a better idea may be to apply it to a particular command:



          git -c color.status=always status -sb


          Putting it all together:



          watch --color git -c color.status=always status -sb





          share|improve this answer













          git uses a configuration value to determine whether to show coloured output or not.



          For example:



          git config --global color.ui auto


          This sets the colour setting to auto globally. In auto mode, git will determine whether it's a real terminal before sending colour codes, as Oli suggested.



          You can force this global value to always, however a better idea may be to apply it to a particular command:



          git -c color.status=always status -sb


          Putting it all together:



          watch --color git -c color.status=always status -sb






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 20 '14 at 15:17









          Drew NoakesDrew Noakes

          2,81842847




          2,81842847























              0














              It works if git (--color) and watch (-c) are told to use colors:



              watch -cd "git branch -va --color"





              share|improve this answer




























                0














                It works if git (--color) and watch (-c) are told to use colors:



                watch -cd "git branch -va --color"





                share|improve this answer


























                  0












                  0








                  0







                  It works if git (--color) and watch (-c) are told to use colors:



                  watch -cd "git branch -va --color"





                  share|improve this answer













                  It works if git (--color) and watch (-c) are told to use colors:



                  watch -cd "git branch -va --color"






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  sjassjas

                  17318




                  17318






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Ask Ubuntu!


                      • 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%2faskubuntu.com%2fquestions%2f423672%2fwhy-dont-git-colours-appear-when-using-watch%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

                      香粉寮

                      GameSpot