From ae841090e1af22820b3b7c2826b303faa0da01b8 Mon Sep 17 00:00:00 2001 From: voitau Date: Thu, 2 Apr 2020 15:47:16 -0700 Subject: [PATCH 1/7] Fix color term dependency --- .github/workflows/unit-tests.yml | 1 - mdlm.sh | 29 +++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 846f5e9..63c415c 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -24,6 +24,5 @@ jobs: - name: Execute unit tests run: | - export TERM=xterm-256color $HOME/opt/bats/bin/bats test/ diff --git a/mdlm.sh b/mdlm.sh index 83c29d5..34dff37 100755 --- a/mdlm.sh +++ b/mdlm.sh @@ -21,11 +21,26 @@ MDLM_IGNORE_END="" MDLM_ADD_LINK="https://github.com/markdown-localization/markdown-localization-spec#workflow" -normal=$'\e[0m' -green=$(tput setaf 2) -red=$(tput setaf 1) -yellow=$(tput setaf 3) -blue=$(tput setaf 6) +USE_COLORS="auto" +normal="" +green="" +red="" +yellow="" +blue="" + +mdlm_setup_colors() { + ncolors="$(tput colors)" + if [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + USE_COLORS="always" + normal=$'\e[0m' + green=$(tput setaf 2) + red=$(tput setaf 1) + yellow=$(tput setaf 3) + blue=$(tput setaf 6) + else + USE_COLORS="never" + fi +} mdlm_echo() { command printf %s\\n "$*" 2>/dev/null @@ -268,7 +283,7 @@ mdlm_update_all_headers() { } mdlm_original_diff() { - diff --color -B \ + diff --color="${USE_COLORS}" -B \ <(grep -v "${MDLM_HEADER}" "${2}" \ | sed -e "/${MDLM_P_CLOSE}/,/${MDLM_P_OPEN}/d" -e "/${MDLM_P_OPEN}/d" -e "/$MDLM_IGNORE_START/,/$MDLM_IGNORE_END/d") \ <(grep -v "${MDLM_HEADER}" "${1}" | sed -e "/${MDLM_IGNORE_START}/,/${MDLM_IGNORE_END}/d") @@ -365,6 +380,8 @@ mdlm_help() { } mdlm() { + mdlm_setup_colors + if [ $# -lt 1 ]; then mdlm help return From e1d634a6fbdd34bbb0461ab56c7e8f95630037bd Mon Sep 17 00:00:00 2001 From: voitau Date: Thu, 2 Apr 2020 16:01:20 -0700 Subject: [PATCH 2/7] Fix color term dependency --- mdlm.sh | 7 +------ test/test-blank.bats | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/mdlm.sh b/mdlm.sh index 34dff37..ff4759c 100755 --- a/mdlm.sh +++ b/mdlm.sh @@ -22,15 +22,10 @@ MDLM_IGNORE_END="" MDLM_ADD_LINK="https://github.com/markdown-localization/markdown-localization-spec#workflow" USE_COLORS="auto" -normal="" -green="" -red="" -yellow="" -blue="" mdlm_setup_colors() { ncolors="$(tput colors)" - if [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + if tty -s && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then USE_COLORS="always" normal=$'\e[0m' green=$(tput setaf 2) diff --git a/test/test-blank.bats b/test/test-blank.bats index e84fbb1..c9824cb 100644 --- a/test/test-blank.bats +++ b/test/test-blank.bats @@ -9,7 +9,6 @@ teardown() { } @test "mdlm - with no arguments" { - $mdlm run $mdlm [ $status -eq 0 ] [ $(expr "$output" : "Markdown Localization Manager (Bash) [0-9][0-9.]*") -ne 0 ] From 3a7ad4ad7a095b2fb7b7f56b1ba59a44ff0622b3 Mon Sep 17 00:00:00 2001 From: voitau Date: Thu, 2 Apr 2020 16:06:34 -0700 Subject: [PATCH 3/7] Fix color term dependency --- mdlm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdlm.sh b/mdlm.sh index ff4759c..6c29579 100755 --- a/mdlm.sh +++ b/mdlm.sh @@ -25,7 +25,7 @@ USE_COLORS="auto" mdlm_setup_colors() { ncolors="$(tput colors)" - if tty -s && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then + if [ -n "${TERM}" ] && [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then USE_COLORS="always" normal=$'\e[0m' green=$(tput setaf 2) From c65bfa2991d44d0da516bdd5364bad75804c6681 Mon Sep 17 00:00:00 2001 From: voitau Date: Thu, 2 Apr 2020 16:13:48 -0700 Subject: [PATCH 4/7] Fix color term dependency --- mdlm.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mdlm.sh b/mdlm.sh index 6c29579..636b3d0 100755 --- a/mdlm.sh +++ b/mdlm.sh @@ -24,16 +24,18 @@ MDLM_ADD_LINK="https://github.com/markdown-localization/markdown-localization-sp USE_COLORS="auto" mdlm_setup_colors() { - ncolors="$(tput colors)" - if [ -n "${TERM}" ] && [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then - USE_COLORS="always" - normal=$'\e[0m' - green=$(tput setaf 2) - red=$(tput setaf 1) - yellow=$(tput setaf 3) - blue=$(tput setaf 6) - else - USE_COLORS="never" + if [ -n "${TERM}" ]; then + ncolors="$(tput colors)" + if [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then + USE_COLORS="always" + normal=$'\e[0m' + green=$(tput setaf 2) + red=$(tput setaf 1) + yellow=$(tput setaf 3) + blue=$(tput setaf 6) + else + USE_COLORS="never" + fi fi } From 94fff021ec47af7fc898765e34c719c0c3b655b9 Mon Sep 17 00:00:00 2001 From: voitau Date: Thu, 2 Apr 2020 16:18:33 -0700 Subject: [PATCH 5/7] Fix color term dependency --- mdlm.sh | 1 + test/test-status.bats | 1 + 2 files changed, 2 insertions(+) diff --git a/mdlm.sh b/mdlm.sh index 636b3d0..aaefb50 100755 --- a/mdlm.sh +++ b/mdlm.sh @@ -24,6 +24,7 @@ MDLM_ADD_LINK="https://github.com/markdown-localization/markdown-localization-sp USE_COLORS="auto" mdlm_setup_colors() { + echo "term: ${TERM}" if [ -n "${TERM}" ]; then ncolors="$(tput colors)" if [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then diff --git a/test/test-status.bats b/test/test-status.bats index 6a80f7c..482d72a 100644 --- a/test/test-status.bats +++ b/test/test-status.bats @@ -9,6 +9,7 @@ teardown() { } @test "mdlm status" { + $mdlm status run $mdlm status [ $status -eq 0 ] [ "${lines[0]}" == 'Localization status for all locales.' ] From bdbe0a1d746f366b9e72b862adda4a4948c5672b Mon Sep 17 00:00:00 2001 From: voitau Date: Thu, 2 Apr 2020 16:22:11 -0700 Subject: [PATCH 6/7] Fix color term dependency --- mdlm.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mdlm.sh b/mdlm.sh index aaefb50..5478b9c 100755 --- a/mdlm.sh +++ b/mdlm.sh @@ -24,8 +24,7 @@ MDLM_ADD_LINK="https://github.com/markdown-localization/markdown-localization-sp USE_COLORS="auto" mdlm_setup_colors() { - echo "term: ${TERM}" - if [ -n "${TERM}" ]; then + if test -t 1; then ncolors="$(tput colors)" if [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then USE_COLORS="always" From 7893a022d836ed78c85c3e289a91a6b56d0e6dab Mon Sep 17 00:00:00 2001 From: voitau Date: Thu, 2 Apr 2020 16:23:48 -0700 Subject: [PATCH 7/7] Fix color term dependency --- .github/workflows/{linting.yml => lint.yml} | 2 +- README.md | 2 +- test/test-status.bats | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) rename .github/workflows/{linting.yml => lint.yml} (94%) diff --git a/.github/workflows/linting.yml b/.github/workflows/lint.yml similarity index 94% rename from .github/workflows/linting.yml rename to .github/workflows/lint.yml index 1f2f7da..356a4cb 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: linting +name: lint on: push: diff --git a/README.md b/README.md index 9327def..c3585f1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/markdown-localization/mdlm-sh) -[![linting](https://github.com/markdown-localization/mdlm-sh/workflows/linting/badge.svg)](https://github.com/markdown-localization/mdlm-sh/actions?query=workflow:linting) +[![lint](https://github.com/markdown-localization/mdlm-sh/workflows/lint/badge.svg)](https://github.com/markdown-localization/mdlm-sh/actions?query=workflow:lint) [![unit-tests](https://github.com/voitau/mdlm-sh/workflows/unit-tests/badge.svg)](https://github.com/markdown-localization/mdlm-sh/actions?query=workflow:unit-tests) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3814/badge)](https://bestpractices.coreinfrastructure.org/projects/3814) diff --git a/test/test-status.bats b/test/test-status.bats index 482d72a..6a80f7c 100644 --- a/test/test-status.bats +++ b/test/test-status.bats @@ -9,7 +9,6 @@ teardown() { } @test "mdlm status" { - $mdlm status run $mdlm status [ $status -eq 0 ] [ "${lines[0]}" == 'Localization status for all locales.' ]