Skip to content

Instantly share code, notes, and snippets.

@nigjo
Last active June 5, 2020 15:20
Show Gist options
  • Save nigjo/51f01247c4f777cbe8f58a9faac1daa5 to your computer and use it in GitHub Desktop.
Save nigjo/51f01247c4f777cbe8f58a9faac1daa5 to your computer and use it in GitHub Desktop.
Set color Env-Vars for Windows Batch scripts. DO NOT COPY PASTE THIS GIST. You should download the file to preserve the ESC characters.
@echo off
REM
REM Licensed to the Apache Software Foundation (ASF) under one
REM or more contributor license agreements. See the NOTICE file
REM distributed with this work for additional information
REM regarding copyright ownership. The ASF licenses this file
REM to you under the Apache License, Version 2.0 (the
REM "License"); you may not use this file except in compliance
REM with the License. You may obtain a copy of the License at
REM
REM http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing,
REM software distributed under the License is distributed on an
REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
REM KIND, either express or implied. See the License for the
REM specific language governing permissions and limitations
REM under the License.
REM
REM (c) by Jens Hofschroeer - nigjo@github.com
REM https://gist.github.com/nigjo/51f01247c4f777cbe8f58a9faac1daa5
REM
REM copy this to your original script and call
REM if exist "%~dp0clicolor.cmd" call "%~dp0clicolor.cmd"
REM
rem see https://bixense.com/clicolors/
if defined CLICOLOR_FORCE if not "%CLICOLOR_FORCE%" == "0" goto :setcolors
if not defined CLICOLOR goto :eof
if "%CLICOLOR%" == "0" goto :eof
rem see Update on https://stackoverflow.com/a/52139735
2>nul (5>&4 break) && (
goto :eof
)
:setcolors
if defined CLICOL_NONE goto :eof
rem see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
set CLICOL_NONE=
set CLICOL_BLACK=
set CLICOL_RED=
set CLICOL_GREEN=
set CLICOL_YELLOW=
set CLICOL_BLUE=
set CLICOL_PURPLE=
set CLICOL_CYAN=
set CLICOL_LGRAY=
set CLICOL_GRAY=
set CLICOL_LRED=
set CLICOL_LGREEN=
set CLICOL_YELLOW=
set CLICOL_LBLUE=
set CLICOL_LPURPLE=
set CLICOL_LCYAN=
set CLICOL_WHITE=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment