When running git-substatus with watch, the output is not clean due to the escape codes:
watch git-substatus
# Every 2.0s: git-substatus
# ^[90m directory: </home/myazici>^[0m
# • ^[1m^[34mdotfiles^[0m ^[4m^[37mv0.4.4^[0m ^[3m^[32m<sync>^[0m ^[36m^[0m ^[35m^[0m
# • ^[1m^[34mtmp-workbench^[0m ^[4m^[37mupdates^[0m ^[33m2 untracked & ahead 1^[0m ^[36m^[0m ^[35m^[0m
With watch git status the color is not there; but, when printed onto the screen, it is.
watch --color git-substatus shows the output with color, but that's a separate parameter added to the watch command.
If I add watch git -c color.status=always status, I see the git status with the escape code.
So how does git know when to add the escape codes?
Answer: there's a way to check if a file is opened on terminal
man test
...
-t FD file descriptor FD is opened on a terminal
...
echo '''
#!/bin/bash
text="Hello world"
if [ -t 1 ]; then
echo "***stdout is a terminal***"
text="$(printf "%s" "\e[31m$text\e[0m")"
fi
echo -e "$text"
''' > test.sh
chmod +x test.sh
./test.sh
# ***stdout is a terminal***
# Hello world
#
watch ./test.sh
# Every 2.0s: ./test.sh
#
# Hello world
#
TODO
Watch 1 time & parse the output.
| watch args |
git-substatus args |
color codes printed |
--color |
--color |
false |
--color |
--no-color |
false |
| `` |
--color |
true |
| `` |
--no-color |
false |
When running
git-substatuswithwatch, the output is not clean due to the escape codes:With
watch git statusthe color is not there; but, when printed onto the screen, it is.watch --color git-substatusshows the output with color, but that's a separate parameter added to thewatchcommand.If I add
watch git -c color.status=always status, I see the git status with the escape code.So how does git know when to add the escape codes?
Answer: there's a way to check if a file is opened on terminal
TODO
--coloralways prints color--no-colornever prints colorwatchWatch 1 time & parse the output.
--color--colorfalse--color--no-colorfalse--colortrue--no-colorfalse