Created
May 20, 2026 02:36
-
-
Save eddy-22/3f840cda751c85afc57946bd096715ea to your computer and use it in GitHub Desktop.
ZSH script for adding colors and styles to text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env zsh | |
| function color() { | |
| local color=$1 style=$2 b=0 | |
| shift | |
| case $style in | |
| bold|b) b=1; shift ;; | |
| italic|i) b=2; shift ;; | |
| underline|u) b=4; shift ;; | |
| inverse|in) b=7; shift ;; | |
| strikethrough|s) b=9; shift ;; | |
| esac | |
| case $color in | |
| black|b) echo "\033[${b};30m${@}\033[0;m" ;; | |
| red|r) echo "\033[${b};31m${@}\033[0;m" ;; | |
| green|g) echo "\033[${b};32m${@}\033[0;m" ;; | |
| yellow|y) echo "\033[${b};33m${@}\033[0;m" ;; | |
| blue|bl) echo "\033[${b};34m${@}\033[0;m" ;; | |
| magenta|m) echo "\033[${b};35m${@}\033[0;m" ;; | |
| cyan|c) echo "\033[${b};36m${@}\033[0;m" ;; | |
| white|w) echo "\033[${b};37m${@}\033[0;m" ;; | |
| *) echo "\033[${b};38;5;$(( ${color} ))m${@}\033[0;m" ;; | |
| esac | |
| } | |
| color "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment