Skip to content

Instantly share code, notes, and snippets.

@minamaged113
Created July 12, 2021 08:25
Show Gist options
  • Save minamaged113/92879073e091239409f3f0ca279f09a4 to your computer and use it in GitHub Desktop.
Save minamaged113/92879073e091239409f3f0ca279f09a4 to your computer and use it in GitHub Desktop.
simple bash function for displaying multicolor output.
function pcolor() {
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
end=$'\e[0m'
printf "${!1}%-6s\n${end}" "$2"
}
# Usage example
# pcolor "red" "This is a red text"
# Importing to another script (given that both are in the same directory)
# cwd="$(dirname "$0")"
# source "$cwd/pcolor.sh"
# pcolor "blu" "hi, this is a blue text"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment