view bin/termcolors.sh @ 682:88888f40c628

[vimrc] Disable indent plugin Less predictable behavior with it enabled.
author nanaya <me@nanaya.pro>
date Fri, 24 Jun 2022 22:50:19 +0900
parents 73e90355bbd7
children
line wrap: on
line source

#!/bin/sh

# Usage:
#   _c [bold_|]<color> <text>
#
#   <color> can be one of:
#     black, blue, green, cyan, red, purple, brown, gray
#   Prefix the color with bold_ to use bold style/light color.
#
# Example:
#   To print word "Hello" in bold blue:
#     _c bold_blue "Hello"
#
#   To print text with only one word colored:
#     echo "Hello, $(c green world)."
#
# To do:
#   Support for background color, underline, etc.
#
# Reference:
#   Colours, http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
#

_c() {
  color_name="${1}"
  shift
  text="${*}"
  esq="\033["
  r="${esq}0m" # r for reset
  case "${color_name}" in
    bold_*) color="1;";;
    *) color="0;";;
  esac
  case "${color_name}" in
    *black) color="${color}30";;
    *blue) color="${color}34";;
    *green) color="${color}32";;
    *cyan) color="${color}36";;
    *red) color="${color}31";;
    *purple) color="${color}35";;
    *brown) color="${color}33";;
    *gray) color="${color}37";;
  esac
  color="${esq}${color}m"
  printf "${color}%s${r}" "${text}"
}