Coder Social home page Coder Social logo

bash-colors's Introduction

Bash Colors

πŸ™ˆ KISS: See kiss-colors.sh for a simpler version πŸ˜‰

Usage

$(c <flags>) inside an echo -e or printf
Or $(c) to reset

cecho <flags> <text> is a shortcut for echo -e "$(c <flags>)<text>$(c)"

Flags

 β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”
 β”‚ Fg/Bg β”‚ Color          β”‚ Octal           β”‚   β”‚ Code  β”‚ Style           β”‚ Octal β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
 β”‚  K/k  β”‚ Black          β”‚ \e[ + 3/4  + 0m β”‚   β”‚  s/S  β”‚ Bold (strong)   β”‚ \e[1m β”‚
 β”‚  R/r  β”‚ Red            β”‚ \e[ + 3/4  + 1m β”‚   β”‚  d/D  β”‚ Dim             β”‚ \e[2m β”‚
 β”‚  G/g  β”‚ Green          β”‚ \e[ + 3/4  + 2m β”‚   β”‚  i/I  β”‚ Italic          β”‚ \e[3m β”‚
 β”‚  Y/y  β”‚ Yellow         β”‚ \e[ + 3/4  + 3m β”‚   β”‚  u/U  β”‚ Underline       β”‚ \e[4m β”‚
 β”‚  B/b  β”‚ Blue           β”‚ \e[ + 3/4  + 4m β”‚   β”‚  f/F  β”‚ Blink (flash)   β”‚ \e[5m β”‚
 β”‚  M/m  β”‚ Magenta        β”‚ \e[ + 3/4  + 5m β”‚   β”‚  n/N  β”‚ Negative        β”‚ \e[7m β”‚
 β”‚  C/c  β”‚ Cyan           β”‚ \e[ + 3/4  + 6m β”‚   β”‚  h/H  β”‚ Hidden          β”‚ \e[8m β”‚
 β”‚  W/w  β”‚ White          β”‚ \e[ + 3/4  + 7m β”‚   β”‚  t/T  β”‚ Strikethrough   β”‚ \e[9m β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€   β”œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€
 β”‚  High intensity        β”‚ \e[ + 9/10 + *m β”‚   β”‚   0   β”‚ Reset           β”‚ \e[0m β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜
                                                 Uppercase = Reset a style: \e[2*m

The single parameter of the function is composed of one or several 1-character flags.
By convention in this order: reset, formats, foreground, background.
Or in regex language: 0?S?[sdiufn-]*[KRGYBMCW]?[krgybmcw]?

Remarks

  • Reset must come before the others… or it will undo immediately the formatting! So $(c 0s) and not $(c s0).
  • @TODO: h for high intensity is not yet implemented.
  • Quite slow 😞

Examples

  • printf "$(c sW)Bold white$(c) and normal"
  • echo -e "Normal text… $(c sRy)BOLD red text on yellow background… $(c w)now on white background… $(c 0u) reset and underline… $(c) and back to normal."
  • cecho Wb "White text on blue background"

References:

License

Licensed under the MIT License.

bash-colors's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.