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/.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/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/mdlm.sh b/mdlm.sh index 83c29d5..5478b9c 100755 --- a/mdlm.sh +++ b/mdlm.sh @@ -21,11 +21,23 @@ 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" + +mdlm_setup_colors() { + if test -t 1; 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 +} mdlm_echo() { command printf %s\\n "$*" 2>/dev/null @@ -268,7 +280,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 +377,8 @@ mdlm_help() { } mdlm() { + mdlm_setup_colors + if [ $# -lt 1 ]; then mdlm help return 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 ]