All Projects → lfkdev → bashtemplate

lfkdev / bashtemplate

Licence: other
A bash template for better bash coding.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to bashtemplate

gem-check
GemCheck: Writing Better Ruby Gems Checklist
Stars: ✭ 77 (+2.67%)
Mutual labels:  styleguide
SFMC-Cookbook
How to survive as a developer for Salesforce Marketing Cloud
Stars: ✭ 70 (-6.67%)
Mutual labels:  styleguide
vf-core
A (primarily CSS) framework that targets needs of life science websites and services
Stars: ✭ 16 (-78.67%)
Mutual labels:  styleguide
gravity-ui-web
Library of styles, components and associated assets to build UIs for the web. Part of buildit's Gravity design system.
Stars: ✭ 20 (-73.33%)
Mutual labels:  styleguide
VBA-Style-Guide
🎮 Style guideline for writing clean and maintainable VBA.
Stars: ✭ 23 (-69.33%)
Mutual labels:  styleguide
melos
A collection of React UI components from YouVersion and the Open Digerati Team
Stars: ✭ 40 (-46.67%)
Mutual labels:  styleguide
styleguide-todo-grammar
/sBin/StyleGuide/ToDo
Stars: ✭ 19 (-74.67%)
Mutual labels:  styleguide
frontend-handbook
Our handbook based on 10 years of experience in Frontend/JS development
Stars: ✭ 45 (-40%)
Mutual labels:  styleguide
oskrhq-design-system
A mostly reasonable although opinionated approach to building responsive Digital Interfaces sharing the same anatomy.
Stars: ✭ 60 (-20%)
Mutual labels:  styleguide
flask-styleguide
A living Styleguide for your Flask application
Stars: ✭ 47 (-37.33%)
Mutual labels:  styleguide
Aurelia-styleguide
Aurelia Style Guide: A starting point for Aurelia development teams to provide consistency through best practices. http://aurelia.io
Stars: ✭ 24 (-68%)
Mutual labels:  styleguide
css-stil-rehberi
CSS ve SASS için makul bir yaklaşım
Stars: ✭ 28 (-62.67%)
Mutual labels:  styleguide
Nitro-Web
Human-Connection - Social Network Frontend
Stars: ✭ 16 (-78.67%)
Mutual labels:  styleguide
ustyle
A living styleguide and pattern library by uSwitch.
Stars: ✭ 18 (-76%)
Mutual labels:  styleguide
papyrum
Papyrum is a tool that will help you in the creation of your design system, style guide or in the documentation of your project based on react
Stars: ✭ 19 (-74.67%)
Mutual labels:  styleguide
guidelines
Guidelines, patterns, and coding styles
Stars: ✭ 16 (-78.67%)
Mutual labels:  styleguide
python
Python Style Guide
Stars: ✭ 49 (-34.67%)
Mutual labels:  styleguide
sonar-gherkin-plugin
SonarQube Cucumber Gherkin Analyzer
Stars: ✭ 33 (-56%)
Mutual labels:  styleguide
decanter
A collection of front end web resources.
Stars: ✭ 31 (-58.67%)
Mutual labels:  styleguide
graphql-guidelines
GraphQL @ Yelp Schema Guidelines
Stars: ✭ 74 (-1.33%)
Mutual labels:  styleguide

Bash template

Use this bash-template for your next script! This will give you cleaner output, better error handling and more features. This script is based on the rules of Googles Styleguide and bahamas10's Styguide

Output example:

There are the following output classes: info, warn, success, debug and error. The classes are structured as follows (info function as example):

info() {
  local _date
  _date=$(date +%d-%H.%M)
  echo -e "[$_date][INFO]: $1 "
} 

So you can easily filter the output your script produces. Example usage:

info " I am some random info."
warn "This is not normal!"
succ "Finished without errors!"
debug "I'm some info just for the devs!"
err "Error, something is wrong!"
err_die "Error, exiting now!"

In addition, some functions have more features than just clean output.

Debug function

The debug() function will only show up if boolean 'is_debug' is true. This is made by the -d parameter. So devs can just execute the script with -d to view all debug messages.

$ bash /usr/local/bin/script.sh -d

Err-Die function

The err_die() function redirects the message to STDERR, starts the cleanup function and then exits. You can call err_die() with "1" as argument to show the help before exiting.

err_die "Please use parameter." 1

You can call normal errors without exiting the script by just

err "This is an error but I can continue anyway."

Traps

The following traps are builtin:

trap exit_EXIT EXIT
trap exit_CTRL QUIT SIGINT

The trap function ensures that the script recognizes if it is aborted by the user (ctrl+c), or if it crashes due to other reasons. As soon as it detects an abort, the cleanup function is started, thus ensuring that the cleanup function also runs in case of unplanned aborts.

This function is ALWAYS started when the script ends. Therefore the cleanup function is not included in the main function.

exit_EXIT() {
  info "Script ended! Cleanup & Exit."
  cleanup
  exit 1
}

This function is called when the user presses ctrl+c.

exit_CTRL() {
  err "User pressed CTRL+C!"
  exit 1
}

Changing Colors

Just change the color pallet values at the top of the script as you whish.

readonly cf="\\033[0m"
readonly red="\\033[0;31m"
readonly green="\\033[0;32m"
readonly yellow="\\033[0;33m"
readonly purple="\\033[0;35m"

Quick Start:

Just download the script

wget -O mynewscript.sh https://raw.githubusercontent.com/lfkdev/bashtemplate/master/template_script.bash
chmod +x mynewscript.sh

Fill your information into the metabox

####################################################
# Author:                                          #
# Info:                                            #
# License:                                         #
####################################################

Now start creating your code with the output functions and write every function in the main one! Have fun

If you have any problems or wishes let me now.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].