Why don't git colours appear when using watch?
When running git status -sb I see:

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:

However for git the colours disappear:
$ watch --color "git status -sb"

So, why does watch show colours from ls but not from git output?
git watch-command
add a comment |
When running git status -sb I see:

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:

However for git the colours disappear:
$ watch --color "git status -sb"

So, why does watch show colours from ls but not from git output?
git watch-command
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
add a comment |
When running git status -sb I see:

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:

However for git the colours disappear:
$ watch --color "git status -sb"

So, why does watch show colours from ls but not from git output?
git watch-command
When running git status -sb I see:

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:

However for git the colours disappear:
$ watch --color "git status -sb"

So, why does watch show colours from ls but not from git output?
git watch-command
git watch-command
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
The following statements are true:
watchruns the command in a new shell,sh.
.bashrcaliaseslsasls --color=autoto enable colours
shdoesn't inherit or usebashaliases.
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.
2
But the OP wants to know why does this not work withgit status -sb, even though it works withls --color.
– jobin
Feb 20 '14 at 15:04
This makes sense. However there's no alias forgit. 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 toautowhich, as you correctly surmised, was causing git to avoid the colour output. Usingalwaysinstead has solved this problem. Many thanks!
– Drew Noakes
Feb 20 '14 at 15:10
add a comment |
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
add a comment |
It works if git (--color) and watch (-c) are told to use colors:
watch -cd "git branch -va --color"
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
The following statements are true:
watchruns the command in a new shell,sh.
.bashrcaliaseslsasls --color=autoto enable colours
shdoesn't inherit or usebashaliases.
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.
2
But the OP wants to know why does this not work withgit status -sb, even though it works withls --color.
– jobin
Feb 20 '14 at 15:04
This makes sense. However there's no alias forgit. 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 toautowhich, as you correctly surmised, was causing git to avoid the colour output. Usingalwaysinstead has solved this problem. Many thanks!
– Drew Noakes
Feb 20 '14 at 15:10
add a comment |
The following statements are true:
watchruns the command in a new shell,sh.
.bashrcaliaseslsasls --color=autoto enable colours
shdoesn't inherit or usebashaliases.
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.
2
But the OP wants to know why does this not work withgit status -sb, even though it works withls --color.
– jobin
Feb 20 '14 at 15:04
This makes sense. However there's no alias forgit. 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 toautowhich, as you correctly surmised, was causing git to avoid the colour output. Usingalwaysinstead has solved this problem. Many thanks!
– Drew Noakes
Feb 20 '14 at 15:10
add a comment |
The following statements are true:
watchruns the command in a new shell,sh.
.bashrcaliaseslsasls --color=autoto enable colours
shdoesn't inherit or usebashaliases.
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.
The following statements are true:
watchruns the command in a new shell,sh.
.bashrcaliaseslsasls --color=autoto enable colours
shdoesn't inherit or usebashaliases.
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.
edited Apr 13 '17 at 12:37
Community♦
1
1
answered Feb 20 '14 at 14:59
Oli♦Oli
224k89567767
224k89567767
2
But the OP wants to know why does this not work withgit status -sb, even though it works withls --color.
– jobin
Feb 20 '14 at 15:04
This makes sense. However there's no alias forgit. 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 toautowhich, as you correctly surmised, was causing git to avoid the colour output. Usingalwaysinstead has solved this problem. Many thanks!
– Drew Noakes
Feb 20 '14 at 15:10
add a comment |
2
But the OP wants to know why does this not work withgit status -sb, even though it works withls --color.
– jobin
Feb 20 '14 at 15:04
This makes sense. However there's no alias forgit. 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 toautowhich, as you correctly surmised, was causing git to avoid the colour output. Usingalwaysinstead 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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Feb 20 '14 at 15:17
Drew NoakesDrew Noakes
2,81842847
2,81842847
add a comment |
add a comment |
It works if git (--color) and watch (-c) are told to use colors:
watch -cd "git branch -va --color"
add a comment |
It works if git (--color) and watch (-c) are told to use colors:
watch -cd "git branch -va --color"
add a comment |
It works if git (--color) and watch (-c) are told to use colors:
watch -cd "git branch -va --color"
It works if git (--color) and watch (-c) are told to use colors:
watch -cd "git branch -va --color"
answered 3 hours ago
sjassjas
17318
17318
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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