Giter VIP home page Giter VIP logo

mecho's Introduction

mecho

mecho is marked up echo. It's a shell function for printing colored and formatted text to the terminal using a simple markup.

mecho "A [red]rose[/] is a [bg_red]rose[/] is a [red][bold][bg_yellow]rose[/]"

screenshot

Or alternatively

# use it like 'echo' with no quotes
mecho boredom [bg_green]unto[/] freedom
# suppress newline at the end with the -n flag
mecho -n "[yellow][bold](User: zer0Cool)[/]"

Installation

Just copy the mecho function into your shell's rc file. Here it is, in full, for bash:

mecho() {
  colors=(black red green yellow blue purple cyan white)
  effects=(reset bold dim italic underline blink rblink reverse)
  if [ "$1" == "-n" ]; then nl=0; shift; else nl=1; fi
  M="$*"; M=${M//\[\/\]/\[reset\]}
  for i in "${!colors[@]}"; do
    M=${M//\[${colors[$i]}\]/\\033[0;3${i}m}
    M=${M//\[bg_${colors[$i]}\]/\\033[4${i}m}
    M=${M//\[${effects[$i]}\]/\\033[${i}m}
  done
  printf -- "$M"
  if [ "$nl" -eq 1 ]; then printf "\n"; fi
}

Also in this repo is the zsh version.

Usage

Much like, echo, mecho takes any number of arguments and prints them to standard output, interpreting a simple markup syntax of [tags] to colors and effects, with an optional newline at the end. The tags are in the form [tag] and [/] to reset.

Colors: black, red, green, yellow, blue, purple, cyan, white

Effects: reset, bold, dim, italic, underline, blink, rblink, reverse

To make a background color, prefix the color with bg_.

To suppress the newline at the end, use the -n flag.

To stack tags, just put them in order, like [color][effect][bg_color]

Markup inspired by rich, in turn inspired by BBCode.

mecho's People

Contributors

sinakhalili avatar

Watchers

 avatar

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.