GithubHelp home page GithubHelp logo

modern.sh's Introduction

modern.sh

Modern helpers for shell scripting.


I end up using a lot of shell scripting for portability and efficiency reasons. As designed it is great for glue logic. But shell scripting has a lot of gaps.

modern.sh fills some of these gaps by providing such capabilities as:

  • Including scripts as libraries - and ensuring they're only loaded once
  • Compatibility stubs and wrappers to ease development between Linux and BSD-like environments
  • Best-practice application of shell commands and features (like safe_cd)
  • Copious user feedback and visual indicators that are easy to read to aid debugability

Usage

There is almost no boilerplate for your entry script to reliably find modern.sh.

If you have modern.sh in your path, you're good to start using it with just:

source "$(which modern.sh)"

If you set it up as a library in a relative path and aren't sure where it might end up, then you'll need to do something like this (where libpath is the relative path from your script):

source "$(dirname "${BASH_SOURCE[0]}")/libpath/modern.sh"

Pretty much every function is documented in doc/help.ansi, just display it in your terminal or an ansi-capable editor to read more:

cat doc/help.ansi

Plans

I've used a lot of these functions for many years, copied from project to project, but this version was extracted from my blacklight programming language build scripts.

While I mainly use fish interactively, modern.sh currently heavily depends on bash-isms due to it being readily available on all platforms I have come into contact as well as having a decent set of primitives to build on. While that has been a safe assumption for the last couple of decades, it is no longer the case. Making it zsh compatible will not be a stretch. Eventually modern.sh will grow a deeper compatibility layer to allow it to run on dash and busybox or similar.

modern.sh's People

Contributors

acook avatar

Watchers

 avatar  avatar

modern.sh's Issues

Handle situations where there is no source file

For example streaming the script over SSH or directly to bash's stdin.

The env vars need to be hoisted to the top of the document, since they're not using any of the modern.sh functions anyway.

From where, the $BASH_SOURCE references need to be replaced with a conditional that still is able to build a reasonable environment, probably just using $PWD instead of the script path.

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.