This repository provides two scripts—one for Bash (colors.sh) and one for PowerShell (colors.ps1)—that make it easy to print colored, styled, and highlighted text in your terminal. These scripts are designed to help you add color and emphasis to your terminal output for better readability, debugging, or presentation.
- Overview
- Features
- Supported Environments
- Installation
- Usage
- Color and Style Reference
- Examples
- Troubleshooting
- License
These scripts define a comprehensive set of color, style, and background variables for use in terminal output. They also provide functions to print text with specific colors, backgrounds, and styles, making it easy to enhance your scripts or command-line tools with visually distinct output.
The Bash script (colors.sh) is designed for use in Linux and macOS terminals, while the PowerShell script (colors.ps1) is tailored for Windows PowerShell and PowerShell Core on Windows.
- Easy-to-use color and style variables for terminal output
- Functions to print text with color, background, and style
- Support for bold, underline, and high-intensity (bright) colors
- Works in both Bash (Linux/macOS) and PowerShell (Windows/macOS)
- Great for scripts, logs, prompts, and more
- Bash: Tested on macOS and Linux terminals
- PowerShell: Tested on Windows PowerShell, PowerShell Core, and macOS
- Clone or Download this repository to your local machine.
- Copy the script you need to your project or source it directly in your shell or script.
git clone https://github.com/yourusername/script-colors.git-
Source the script in your Bash session or script:
source /path/to/colors.sh -
Use color variables in your
echocommands:echo -e "${RED}This is red text${RESET}"
-
Use provided functions for more advanced output:
print_line $GREEN "Success!" print_line_color_bg $YELLOW $BG_BLUE "Warning with blue background" print_line_color_style $RED $BOLD "Bold red text"
-
Dot-source the script in your PowerShell session or script:
. /path/to/colors.ps1
-
Use color variables in your
Write-Hostcommands:Write-Host -NoNewline "$RED This is red text $RESET"
-
Use provided functions for more advanced output:
Write-Color $GREEN "Success!" Write-ColorBgCombo $YELLOW $BG_BLUE "Warning with blue background" Write-ColorStyle $RED $BOLD "Bold red text" Write-ColorBgStyleUnderline $WHITE $BG_RED $BOLD "Critical!"
Both scripts define variables for:
- Standard colors (black, red, green, yellow, blue, purple, cyan, white)
- Bold colors
- Underline colors
- High intensity (bright) colors
- High intensity backgrounds
- Bold high intensity colors and backgrounds
- Reset (
RESET) to clear formatting
Variable names are in ALL_CAPS and are self-explanatory.
echo -e "${BOLD_RED}Error:${RESET} Something went wrong."
print_line $UNDERLINE_GREEN "This is underlined green text."
print_line_color_bg_style $WHITE $BG_RED $BOLD "Critical!"Write-Host -NoNewline "$BOLD_RED Error: $RESET Something went wrong."
Write-Color $UNDERLINE_GREEN "This is underlined green text."
Write-ColorBgStyle $WHITE $BG_RED $BOLD "Critical!"- If colors do not appear as expected, ensure your terminal supports ANSI escape codes.
- On Windows, use Windows Terminal, PowerShell Core, or enable Virtual Terminal Processing for best results.
- Always use the
RESETvariable at the end of your colored output to avoid color bleed.
This is expected! The color and style variables are defined for you to use in your own scripts or interactively. The script itself does not reference them internally, so static analysis tools may warn that they are unused. You can safely ignore these warnings.
This project is licensed under the GNU General Public License v3. See the LICENSE file for details.