Giter Site home page Giter Site logo

efunctions's Introduction

efunctions

Port of Gentoo's functions.sh to other *nixes.

Gentoo provides a number of functions for providing feedback on scripts and services. This is a port of those functions to other linuxes such as Ubuntu, so that scripts continue to work.

![Screenshot of efunctions test.sh] (http://cl.ly/image/2n061s1g3y3t/efunctions%20screenshot.png)

Getting started

Installation

Check out this repository to a safe place - we'd suggest /opt/efunctions, but it's up to you. Then run the installation script.

git clone https://github.com/marcusatbang/efunctions.git /opt/efunctions
cd /opt/efunctions
sudo ./install.sh

This will place a symlink in the traditional place used by Gentoo's functions.sh.

Scripts

Use it in your own scripts with:

#!/bin/sh
. /etc/init.d/functions.sh

Note that bash is quite forgiving with how source files are included, while simpler shells like dash can be more restrictive.

If you want to gain access to the colour code variables, use:

#!/bin/sh
. /etc/init.d/functions.sh
eval $(eval_ecolors)

Commands

einfo, ewarn, eerror

Output a message prefixed with a green, yellow or red asterisk.

einfo "Stuff happens"
ewarn "Dangerous stuff happens"
eerror "Oh noes!"
 * Some message
 * Dangerous stuff happens
 * Oh noes!

(GitHub-flavour markdown doesn't support colours...)

einfon, ewarnn, eerrorn

The same as above, but without the newline at the end of each.

einfon "Stuff happens"
ewarnn "Dangerous stuff happens"
eerrorn "Oh noes!"
 * Some message * Dangerous stuff happens * Oh noes!

ebegin, eend

ebegin outputs a message like einfo, with a trailing ellipsis ...

eend appends a good or bad message to the previous line. It's often called with $?, a variable representing the return value of the last command

ebegin Rejigging the squinks
somecommand
eend $?
 * Rejigging the squinks...                                              [ ok ]

eindent, eoutdent

Increase or decrease the indent on subsequent messages.

einfo "Doing three things"
eindent

ebegin "First thing"
firstcommand
eend $?

ebegin "Second thing"
secondcommand
eend $?

ebegin "Third thing"
thirdcommand
eend $?

eoutdent
einfo "Done"
 * Doing three things
   * First thing...                                                      [ ok ]
   * Second thing...                                                     [ ok ]
   * Third thing...                                                      [ ok ]

eval_ecolors

Evaluate this to get access to the colours it uses.

eval $(eval_ecolors)
echo "$GOOD green $WARN yellow $BAD red"
 green  yellow  red

Non-standard commands

The following commands aren't part of the traditional package, but they're useful so I've added them anyway.

eprefix

Prefixes stdin with the current indent.

eindent
eindent
eindent
somecommand | eprefix
       Command output, prefixed with spaces

If you also add the word info, warn or error, it'll prefix stdin with the appropriate asterisk.

eindent
eindent
eindent
somecommand | eprefix info
       * Command output, prefixed with spaces and an asterisk

efunctions's People

Contributors

marcus-downing avatar tommarshall avatar marineam avatar voldemarlegrand avatar

Watchers

Lucy Llewellyn avatar  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.