Skip to content

ingroxd/sheli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SHELI

SHell Extensible Library (sheli) helps you build your scripts. In particular it takes care of those repetitive tasks, such as parameters management and variables settings.

It adds some automatisms, such as the main function, signals management (traps), and some more things. It also comes with a custom version of argparse.

SHELI IS SCRUMPADOOCHOUS!*

Wherever possible, POSIX standards are used, BUT sometimes they are not (a.k.a. local vars et similia).

In this repo a TL;DR will eventually be included with the methods intended to be used.

Getting Started

Prerequisites

Please, read all this readme (yes, including notes, you lazy chap!).

You should have installed BASH in order to let sheli work fine, but if you don't want to install bash, you can easily change the shebang in each lib with the following command (in sheli dir):

find . -type f -name '*.sh' -exec sed -i -e 's|#!/bin/.*sh|#!/bin/dash|' "{}" \;

Theoretically, you can leave shebangs as they are if you are using something that isn't BASH as interpreter for your script.

(DASH is tested and should be fine, although it is not fully tested.)

Installing

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

First of all, clone the repo:

git clone https://github.com/ingroxd/sheli.git

This is actually all you need to do to install it, but you probably want to use a common path for your libs.

I usually put it in ~/Documents and create a symbolic link in /opt, because f**k ~/.local/lib, right? Joking, better use some standard; I'm saving it in ~/.local/lib/sheli:

mkdir -p ~/.local/lib
git clone https://github.com/ingroxd/sheli.git ~/.local/lib/sheli

This is personal and you can (should, actually) use the path you prefer the most.

Running the tests

In order to use it, just put in your script the following:

readonly SHELI_DIR='/path/to/sheli'
. "${SHELI_DIR}/sheli.sh"

Please, note that $SHELI_DIR is mandatory and an error will be thrown if not declared.

Try copy-pasting this short script:

#!/bin/bash

readonly SHELI_DIR=~/.local/lib/sheli
. "${SHELI_DIR}/sheli.sh"

sheli__main "${@}"

If everything works as intended, you will have an error for NOT having a main function.

Deployment

In your script, you have to declare some variables and some functions. In the repo there is an example script with additional memos.

Long story short, all you have to declare are the options your script needs (through argparse) and a main function.

The function main() is mandatory and an error will be thrown if not declared.

Optionally, you can declare functions as trap__int, trap__cleanup, trap__die, etc.

Contributing

If you think something could be more flexible/yellow/robust/modular/fast/something, please, you are welcome to suggest/edit/fork/whatever in order to help this project grow!

I will be happy to explain why I made some strange choices in coding, but I will be happier to hear suggestions and some healthy criticism to improve code and myself.

Authors

  • Gregorio Casa - Initial work - ingroxd

See also the list of contributors who participated in this project.

License

This project is licensed under the GNU-GPLv3 License - see the LICENSE.md file for details

Acknowledgments

  • This project was born because of those repetitive tasks I always have to write for every script.
  • Please, bear in mind that the aim of this project is NOT efficiency (in terms of speed).
  • Warning: not actually scrumpadoochous

About

SHell Extensible Library to help you write your shell scripts

Topics

Resources

License

Stars

Watchers

Forks

Languages