Giter Club home page Giter Club logo

shml's Introduction

shml

shml.sh is a shell framework for faster and easier script development.

Why

HTML has CSS, terminals have "ANSI/VT100 Control Sequences". SHML makes is easy to apply some style to your shell scripts without trying to remember that Yellow = \033[33m instead Yellow is $(color yellow).

How

Run ./shml.sh for usage/help.

Examples

Font Color

For the first example we are going to make the text red.

#!/usr/bin/env bash
source ./shml.sh

echo "
$(color red)
Couldn’t peep it with a pair of bi-focals.
$(color end)
"

Result

Red Text

Background Color

For the second example we are going to make the background red.

echo "
$(background red "I'm no joker, play me as a joker")
"

Result

Red Text

Icons

In this example we are going to illustrate Pass and Fail Messages using colors and icons

echo "
$(color green) Pass $(icon check) $(color end)
$(color red) Fail $(icon xmark) $(color end)
"

Result

Pass Fail

Horizontal Rule Element

In this example we are going to create 5 hr elements.

echo "
$(color green)
10 $(hr '-' 10)
20 $(hr '*' 20)
30 $(hr '~' 30)
40 $(hr '#' 40)
50 $(hr '_' 50)
$(color end)
"

Result

Green HR

Dev

Run tests with make.

Extras

To include the core of shml.sh in to another project (and be able to update it) via a script do the following...

  1. Add the following to your_script.sh
#SHML:START

#SHML:END
  1. Create update_shml.sh with the following (replacing your_script.sh with your actual script name):
#!/usr/bin/env bash
SCRIPT_NAME="your_script.sh"
set -xue
curl -L https://raw.github.com/odb/shml/master/shml.sh > shml.sh
awk '/SHML:START/,/SHML:END/' shml.sh | grep -v "SHML:\(START\|END\)" > tmp
mv tmp shml.sh
awk 'FNR==NR{ _[++d]=$0;next}; /SHML:START/{ print; for(i=1;i<=d;i++){ print _[i] }; f=1;next; }; /SHML:END/{f=0}!f' shml.sh $SCRIPT_NAME > tmp
mv tmp $SCRIPT_NAME
chmod 755 $SCRIPT_NAME
rm shml.sh
  1. Run: bash ./update_shml.sh any time you want the latest code.

Note: While this isn't offically supported, any tweaks/improvments to this method are welcome via an issue labeled 'Enhancment' or by a PR to the readme. Thanks!

shml's People

Contributors

jdorfman avatar jmervine avatar

Watchers

Fabian Arrotin avatar James Cloos 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.